/** * Perform update * * @return void */ protected function update() { echo 'System Update' . PHP_EOL; echo '-------------' . PHP_EOL; echo PHP_EOL; if (!isset($this->args[2])) { $this->argNotFound('update'); } else { if (!in_array($this->args[2], $this->arguments['update'])) { $this->argInvalid('update', $this->args[2]); } else { $type = $this->args[2]; $name = isset($this->args[3]) ? $this->args[3] : 'phire'; $version = null; if ($type == 'system') { $version = \Phire\Project::VERSION; } else { $ext = Table\Extensions::findBy(array('name' => $name)); if (isset($ext->id)) { $assets = unserialize($ext->assets); $version = $assets['info']['Version']; } } $format = null; $formats = \Pop\Archive\Archive::formats(); if (isset($formats['zip'])) { $format = 'zip'; } else { if (isset($formats['tar']) && isset($formats['gz'])) { $format = 'tar.gz'; } } $writable = false; if ($type == 'system' && is_writable(__DIR__ . '/../../../../')) { $writable = true; } else { if ($type == 'module' && is_writable(__DIR__ . '/../../../../../' . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules')) { $writable = true; } } if ($writable) { $config = new Model\Config(); $config->getUpdate(array('type' => $type, 'name' => $name, 'version' => $version, 'format' => $format), true); if (null !== $config->error) { echo ' ' . strip_tags($config->error) . PHP_EOL . PHP_EOL; } else { echo ' ' . strip_tags($config->msg) . PHP_EOL . PHP_EOL; } } else { echo ' The ' . $type . ' folder must be writable to perform the update.' . PHP_EOL . PHP_EOL; } } } }
/** * Install modules method * * @throws \Phire\Exception * @return void */ public function installModules() { try { $path = BASE_PATH . APP_URI; if ($path == '') { $path = '/'; } $modulePath1 = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules'; $modulePath2 = __DIR__ . '/../../../../../module'; $formats = Archive::formats(); $phireCookie = null; foreach ($this->data['new'] as $name => $module) { $ext = substr($module, strrpos($module, '.') + 1); if (array_key_exists($ext, $formats)) { $modPath = file_exists($modulePath1 . '/' . $module) ? $modulePath1 : $modulePath2; if (!is_writable($modPath)) { throw new \Phire\Exception($this->i18n->__('The modules folder is not writable.')); } $archive = new Archive($modPath . '/' . $module); $archive->extract($modPath . '/'); if ((stripos($module, 'gz') || stripos($module, 'bz')) && file_exists($modPath . '/' . $name . '.tar')) { unlink($modPath . '/' . $name . '.tar'); } $dbType = Table\Extensions::getSql()->getDbType(); if ($dbType == \Pop\Db\Sql::SQLITE) { $type = 'sqlite'; } else { if ($dbType == \Pop\Db\Sql::PGSQL) { $type = 'pgsql'; } else { $type = 'mysql'; } } $sqlFile = $modPath . '/' . $name . '/data/' . strtolower($name) . '.' . $type . '.sql'; $cfg = null; $tables = array(); $info = array(); // Check for a config and try to get info out of it if (file_exists($modPath . '/' . $name . '/config') && file_exists($modPath . '/' . $name . '/config/module.php')) { $cfg = file_get_contents($modPath . '/' . $name . '/config/module.php'); if (strpos($cfg, '*/') !== false) { $cfgHeader = substr($cfg, 0, strpos($cfg, '*/')); $cfgHeader = substr($cfgHeader, strpos($cfgHeader, '/*') + 2); $cfgHeaderAry = explode("\n", $cfgHeader); foreach ($cfgHeaderAry as $line) { if (strpos($line, ':')) { $ary = explode(':', $line); if (isset($ary[0]) && isset($ary[1])) { $key = trim(str_replace('*', '', $ary[0])); $value = trim(str_replace('*', '', $ary[1])); $info[$key] = $value; } } } } } if (file_exists($sqlFile)) { // Get any tables required and created by this module $sql = file_get_contents($sqlFile); $tables = array(); $matches = array(); preg_match_all('/^CREATE TABLE(.*)$/mi', $sql, $matches); if (isset($matches[0]) && isset($matches[0][0])) { foreach ($matches[0] as $table) { if (strpos($table, '`') !== false) { $table = substr($table, strpos($table, '`') + 1); $table = substr($table, 0, strpos($table, '`')); } else { if (strpos($table, '"') !== false) { $table = substr($table, strpos($table, '"') + 1); $table = substr($table, 0, strpos($table, '"')); } else { if (strpos($table, "'") !== false) { $table = substr($table, strpos($table, "'") + 1); $table = substr($table, 0, strpos($table, "'")); } else { if (stripos($table, 'EXISTS') !== false) { $table = substr($table, stripos($table, 'EXISTS') + 6); } else { $table = substr($table, stripos($table, 'TABLE') + 5); } if (strpos($table, '(') !== false) { $table = substr($table, 0, strpos($table, '(')); } $table = trim($table); } } } $tables[] = str_replace('[{prefix}]', DB_PREFIX, $table); } } $ext = new Table\Extensions(array('name' => $name, 'file' => $module, 'type' => 1, 'active' => 1, 'assets' => serialize(array('tables' => $tables, 'info' => $info)))); $ext->save(); // If DB is SQLite if (stripos($type, 'Sqlite') !== false) { $dbName = realpath($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/.htphire.sqlite'); $dbUser = null; $dbPassword = null; $dbHost = null; $installFile = $dbName; } else { $dbName = DB_NAME; $dbUser = DB_USER; $dbPassword = DB_PASS; $dbHost = DB_HOST; $installFile = null; } $db = array('database' => $dbName, 'username' => $dbUser, 'password' => $dbPassword, 'host' => $dbHost, 'prefix' => DB_PREFIX, 'type' => DB_INTERFACE == 'Pdo' ? 'Pdo_' . ucfirst(DB_TYPE) : DB_INTERFACE); Dbs::install($dbName, $db, $sqlFile, $installFile, true, false); } else { $ext = new Table\Extensions(array('name' => $name, 'type' => 1, 'active' => 1, 'assets' => serialize(array('tables' => $tables, 'info' => $info)))); $ext->save(); } if (null !== $cfg) { $config = (include $modPath . '/' . $name . '/config/module.php'); if (null !== $config[$name]->install) { $installFunc = $config[$name]->install; $installFunc(); } } if (php_sapi_name() != 'cli') { $cookie = Cookie::getInstance(array('path' => $path)); if (isset($cookie->phire)) { if (null === $phireCookie) { $phireCookie = $cookie->phire; } $i18n = file_exists($modPath . '/' . $name . '/data/assets/i18n'); $modules = (array) $phireCookie->modules; $modules[] = array('name' => $name, 'i18n' => $i18n); $phireCookie->modules = $modules; } } } } if (null !== $phireCookie) { $cookie = Cookie::getInstance(array('path' => $path)); $cookie->set('phire', $phireCookie); } } catch (\Exception $e) { $this->data['error'] = $e->getMessage(); } }
/** * Config update method * * @return void */ public function update() { $this->prepareView('update.phtml', array('assets' => $this->project->getAssets(), 'acl' => $this->project->getService('acl'), 'phireNav' => $this->project->getService('phireNav'))); if (null !== $this->request->getQuery('module')) { $type = 'module'; $name = $this->request->getQuery('module'); $version = null; $title = $this->view->i18n->__('Module Update') . ' ' . $this->view->separator . ' ' . $name; $linkParam = '&module=' . $name; $ext = Table\Extensions::findBy(array('name' => $name)); if (isset($ext->id)) { $assets = unserialize($ext->assets); $version = $assets['info']['Version']; } } else { if (null !== $this->request->getQuery('theme')) { $type = 'theme'; $name = $this->request->getQuery('theme'); $version = null; $title = $this->view->i18n->__('Theme Update') . ' ' . $this->view->separator . ' ' . $name; $linkParam = '&theme=' . $name; $ext = Table\Extensions::findBy(array('name' => $name)); if (isset($ext->id)) { $assets = unserialize($ext->assets); $version = $assets['info']['Version']; } } else { $type = 'system'; $name = 'phire'; $version = \Phire\Project::VERSION; $title = $this->view->i18n->__('System Update'); $linkParam = null; } } $format = null; $formats = \Pop\Archive\Archive::formats(); if (isset($formats['zip'])) { $format = 'zip'; } else { if (isset($formats['tar']) && isset($formats['gz'])) { $format = 'tar.gz'; } } $this->view->set('title', $this->view->i18n->__('Configuration') . ' ' . $this->view->separator . ' ' . $title); $config = new Model\Config(); $writable = false; if ($type == 'system' && is_writable(__DIR__ . '/../../../../../../../')) { $writable = true; } else { if ($type == 'module' && is_writable(__DIR__ . '/../../../../../../../../' . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules')) { $writable = true; } else { if ($type == 'theme' && is_writable(__DIR__ . '/../../../../../../../../' . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes')) { $writable = true; } } } if ($writable) { if (null !== $this->request->getQuery('writable')) { $config->getUpdate(array('type' => $type, 'name' => $name, 'version' => $version, 'format' => $format)); if (null !== $config->error) { $this->view->set('msg', $config->error); $this->send(); } else { $this->view->set('msg', $config->msg); $this->send(); } } else { $link = $this->request->getFullUri() . '?writable=1' . $linkParam; $form = '<div id="update-form">' . $this->view->i18n->__('The %1 folder has been detected as writable.', $type) . ' ' . $this->view->i18n->__('You can proceed with the %1 update by clicking the update button below.', $type) . '<br /><br /><a href="' . $link . '" class="save-btn" style="display: block; width: 220px; height: 20px; color: #fff; text-decoration: none;">' . $this->view->i18n->__('UPDATE') . '</a></div>'; $this->view->set('form', $form); $this->send(); } } else { $form = new Form\Update($this->request->getBasePath() . $this->request->getRequestUri(), 'post', $type, $name, $version, $format); if ($this->request->isPost()) { $form->setFieldValues($this->request->getPost(), array('htmlentities' => array(ENT_QUOTES, 'UTF-8'))); if ($form->isValid()) { $config->getUpdate($this->request->getPost()); if (null !== $config->error) { $this->view->set('msg', $config->error); $this->send(); } else { $this->view->set('msg', $config->msg); $this->send(); } } else { $this->view->set('form', $form); $this->send(); } } else { $this->view->set('form', $form); $this->send(); } } }