public function getDbConnection() { if (!BgPlugin::$con) { BgPlugin::$con = new CDbConnection('sqlite:' . dirname(__FILE__) . '/../runtime/bukget.sqlite'); BgPlugin::$con->createCommand('create table if not exists `updated`' . ' (`name` text primary key not null, `time` integer not null)')->execute(); BgPlugin::$con->createCommand('create table if not exists `category_plugin`' . ' (`category` text, `plugin` text, unique(`category`,`plugin`))')->execute(); BgPlugin::$con->createCommand('create table if not exists `category` (`name` text, unique(`name`))')->execute(); BgPlugin::$con->createCommand('create table if not exists `plugin`' . ' (`name` text primary key, `plugin_name` text, `status` text, `link` text,' . ' `desc` text, `categories` text, unique(`name`))')->execute(); } return BgPlugin::$con; }
public function actionBgPlugin($id, $name, $installed = false, $action = '') { if (Yii::app()->params['use_bukget'] !== true) { throw new CHttpException(404, Yii::t('mc', 'The requested page does not exist.')); } Yii::app()->user->can($id, 'edit configs', true); $model = $this->loadModel($id); $plugin = BgPlugin::model()->findByAttributes(array('name' => $name)); $info = BgPluginInfo::model()->findByPk(array('server_id' => $model->id, 'name' => $plugin->name)); if ($info) { $info->plugin = $plugin; } if (isset($_POST['ajax'])) { switch ($_POST['ajax']) { case 'get_status': $i = $info ? $info->installed : ''; if ($info && $info->disabled) { $i = 'disabled'; } echo CJSON::encode($i); break; } Yii::app()->end(); } if (isset($_POST['action'])) { $action = $_POST['action']; switch ($action) { case 'install': case 'update': if (!McBridge::get()->serverCmd($id, 'bgplugin install:' . $this->esc($name) . ':' . $this->esc($plugin->version) . ':' . $plugin->downloadLink)) { Yii::app()->user->setFlash('server', Yii::t('mc', 'Failed to {action} plugin', array('{action}' => $action)) . ': ' . CHtml::encode(McBridge::get()->lastError())); } break; case 'remove': case 'enable': case 'disable': if (!McBridge::get()->serverCmd($id, 'bgplugin ' . $action . ':' . $this->esc($name))) { Yii::app()->user->setFlash('server', Yii::t('mc', 'Failed to {action} plugin', array('{action}' => $action)) . ': ' . CHtml::encode(McBridge::get()->lastError())); } break; } $this->redirect(array('bgPlugin', 'id' => $id, 'name' => $name, 'action' => $action)); } $this->render('bgPlugin', array('model' => $model, 'plugin' => $plugin, 'info' => $info, 'installed' => $installed, 'action' => $action)); }