本文整理汇总了PHP中Schema::sql方法的典型用法代码示例。如果您正苦于以下问题:PHP Schema::sql方法的具体用法?PHP Schema::sql怎么用?PHP Schema::sql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Schema
的用法示例。
在下文中一共展示了Schema::sql方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: remove
/**
* 删除模块
*
* @param string $module 模块名称
* @param int $removeData 删除模块数据
*
* @return bool
*/
public function remove($module, $removeData = 0)
{
//删除封面关键词数据
if ($removeData) {
//本地安装的模块删除处理
$xmlFile = 'addons/' . $module . '/manifest.xml';
if (is_file($xmlFile)) {
$manifest = Xml::toArray(file_get_contents($xmlFile));
//卸载数据
$installSql = trim($manifest['manifest']['uninstall']['@cdata']);
if (!empty($installSql)) {
if (preg_match('/.php$/', $installSql)) {
$file = 'addons/' . $module . '/' . $installSql;
if (!is_file($file)) {
$this->error = '卸载文件:' . $file . '不存在';
return;
}
require $file;
} else {
\Schema::sql($installSql);
}
}
}
//删除模块回复规则列表
$rids = Db::table('rule')->where('module', $module)->lists('rid') ?: [];
foreach ($rids as $rid) {
service('WeChat')->removeRule($rid);
}
//删除站点模块
Db::table('site_modules')->where('module', $module)->delete();
//模块设置
Db::table('module_setting')->where('module', $module)->delete();
//代金券使用的模块
Db::table('ticket_module')->where('module', $module)->delete();
}
//删除模块数据
$this->where('name', $module)->delete();
//删除模块动作数据
Db::table('modules_bindings')->where('module', $module)->delete();
//更新套餐数据
$package = Db::table('package')->get();
if ($package) {
foreach ($package as $p) {
$p['modules'] = unserialize($p['modules']) ?: [];
if ($k = array_search($_GET['module'], $p['modules'])) {
unset($p['modules'][$k]);
}
$p['modules'] = serialize($p['modules']);
Db::table('package')->where('id', $p['id'])->update($p);
}
}
//更新所有站点缓存
service('site')->updateAllCache();
return TRUE;
}
示例2: cache
public function cache()
{
$table = c('database.prefix') . c('cache.mysql.table');
if (Schema::tableExists(c('cache.mysql.table'))) {
$this->error('Table already exists');
}
$sql = <<<sql
CREATE TABLE `{$table}` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` char(20) DEFAULT NULL,
`data` mediumtext,
`create_at` int(10),
`expire` int(10),
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
sql;
Schema::sql($sql);
}
示例3: install
public function install()
{
//模块安装检测
if ($m = $this->module->where('name', $_GET['module'])->first() || is_dir('module/' . $_GET['module'])) {
message($m['title'] . '模块已经安装或已经存在系统模块, 你可以卸载后重新安装', 'back', 'error');
}
if (IS_POST) {
//获取模块xml数据
$xmlFile = 'addons/' . $_POST['module'] . '/manifest.xml';
$manifest = Xml::toArray(file_get_contents($xmlFile));
$platform = $manifest['manifest']['platform'];
//添加数据
$installSql = trim($manifest['manifest']['install']['@cdata']);
if (!empty($installSql)) {
if (preg_match('/.php$/', $installSql)) {
$file = 'addons/' . $_POST['module'] . '/' . $installSql;
if (!is_file($file)) {
message('安装文件:' . $file . " 不存在", 'back', 'error');
}
require $file;
} else {
\Schema::sql($installSql);
}
}
//不需要对用户关键词进行响应的消息类型
$subscribes = [];
if (!empty($platform['subscribes'])) {
//只选择一个类型
if (isset($platform['subscribes']['message']['@value'])) {
$subscribes[] = $platform['subscribes']['message']['@attributes']['type'];
} else {
foreach ($platform['subscribes']['message'] as $m) {
$subscribes[] = $m['@attributes']['type'];
}
}
}
//需要模块处理的微信关键词消息类型
$processors = [];
if (!empty($platform['processors'])) {
//只选择一个类型
if (isset($platform['processors']['message']['@value'])) {
$subscribes[] = $platform['processors']['message']['@attributes']['type'];
} else {
foreach ($platform['processors']['message'] as $m) {
$processors[] = $m['@attributes']['type'];
}
}
}
//整合添加到模块表中的数据
$moduleData = ['name' => $manifest['manifest']['application']['name']['@cdata'], 'version' => $manifest['manifest']['application']['version']['@cdata'], 'industry' => $manifest['manifest']['application']['industry']['@cdata'], 'title' => $manifest['manifest']['application']['title']['@cdata'], 'url' => $manifest['manifest']['application']['url']['@cdata'], 'resume' => $manifest['manifest']['application']['resume']['@cdata'], 'detail' => $manifest['manifest']['application']['detail']['@cdata'], 'author' => $manifest['manifest']['application']['author']['@cdata'], 'rule' => $manifest['manifest']['application']['rule']['@attributes']['embed'] == 'true' ? 1 : 0, 'thumb' => $manifest['manifest']['application']['thumb']['@cdata'], 'cover' => $manifest['manifest']['application']['cover']['@cdata'], 'is_system' => 0, 'subscribes' => serialize($subscribes), 'processors' => serialize($processors), 'setting' => $manifest['manifest']['application']['@attributes']['setting'] == 'true' ? 1 : 0, 'permissions' => serialize(preg_split('/\\n/', $manifest['manifest']['permission']['@cdata']))];
$moduleData['locality'] = !is_file('addons/' . $_POST['module'] . '/cloud.hd') ? 1 : 0;
Db::table('modules')->insertGetId($moduleData);
//添加模块动作表数据
if (!empty($manifest['manifest']['bindings'])) {
foreach ($manifest['manifest']['bindings'] as $entry => $bind) {
foreach ($bind as $b) {
if (isset($b['@value'])) {
//只有一个元素
$data = ['module' => $manifest['manifest']['application']['name']['@cdata'], 'entry' => $entry, 'title' => $b['@attributes']['title'], 'do' => $b['@attributes']['do'], 'data' => $b['@attributes']['data'], 'directly' => $b['@attributes']['directly'] ? 1 : 0];
Db::table('modules_bindings')->insert($data);
} else {
foreach ($b as $m) {
$data = ['module' => $manifest['manifest']['application']['name']['@cdata'], 'entry' => $entry, 'title' => $m['@attributes']['title'], 'do' => $m['@attributes']['do'], 'data' => $m['@attributes']['data'], 'directly' => $m['@attributes']['directly'] ? 1 : 0];
Db::table('modules_bindings')->insert($data);
}
}
}
}
}
//在服务套餐中添加模块
if (!empty($_POST['package'])) {
$package = Db::table('package')->whereIn('name', $_POST['package'])->get();
foreach ($package as $p) {
$p['modules'] = unserialize($p['modules']);
if (empty($p['modules'])) {
$p['modules'] = [];
}
$p['modules'][] = $_POST['module'];
$p['modules'] = serialize(array_unique($p['modules']));
Db::table('package')->where('name', $p['name'])->update($p);
}
}
service('site')->updateAllCache();
message("模块安装成功", u('installed'));
}
$xmlFile = 'addons/' . $_GET['module'] . '/manifest.xml';
if (is_file($xmlFile)) {
//本地应用
$manifest = Xml::toArray(file_get_contents($xmlFile));
} else {
//下载模块目录
go(u('download', ['module' => $_GET['module']]));
}
$package = Db::table('package')->get();
return view()->with('module', $manifest['manifest'])->with('package', $package);
}