Пример #1
0
 public static function dump()
 {
     $ret = '';
     if (!isset(\Kwf_Setup::$configClass)) {
         throw new Exception("Run Kwf_Setup::setUp() before using this method");
     }
     $dbConfig = \Kwf_Registry::get('dao')->getDbConfig();
     $cacheTables = \Kwf_Util_ClearCache::getInstance()->getDbCacheTables();
     $dumpCmd = "mysqldump";
     $dumpCmd .= " --host=" . escapeshellarg($dbConfig['host']);
     $dumpCmd .= " --user="******" --password="******" --ignore-table=" . escapeshellarg($dbConfig['dbname'] . '.' . $t);
     }
     $cmd .= " {$dbConfig['dbname']}";
     $process = new Process($cmd);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new \RuntimeException($process->getErrorOutput());
     }
     $ret .= $process->getOutput();
     foreach ($cacheTables as $t) {
         $cmd = $dumpCmd;
         $cmd .= " --no-data " . escapeshellarg($dbConfig['dbname']) . " " . escapeshellarg($t);
         $process = new Process($cmd);
         $process->run();
         if (!$process->isSuccessful()) {
             throw new \RuntimeException($process->getErrorOutput());
         }
         $ret .= $process->getOutput();
     }
     return $ret;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     \Kwf_Setup::setUp();
     $dbConfig = \Kwf_Registry::get('dao')->getDbConfig();
     $cacheTables = \Kwf_Util_ClearCache::getInstance()->getDbCacheTables();
     $dumpCmd = "mysqldump";
     $dumpCmd .= " --host=" . escapeshellarg($dbConfig['host']);
     $dumpCmd .= " --user="******" --password="******" --ignore-table=" . escapeshellarg($dbConfig['dbname'] . '.' . $t);
     }
     $cmd .= " {$dbConfig['dbname']}";
     passthru($cmd, $ret);
     if ($ret) {
         return $ret;
     }
     foreach ($cacheTables as $t) {
         $cmd = $dumpCmd;
         $cmd .= " --no-data " . escapeshellarg($dbConfig['dbname']) . " " . escapeshellarg($t);
         passthru($cmd, $ret);
         if ($ret) {
             return $ret;
         }
     }
     return 0;
 }
 public function indexAction()
 {
     if (!file_exists('build/assets')) {
         throw new Kwf_Exception_Client("Installation incomplete: 'build' folder does not exist. You can generate it by calling 'php bootstrap.php build' on commandline. On production servers you should upload locally generated build.");
     }
     $this->view->typeNames = Kwf_Util_ClearCache::getInstance()->getTypeNames();
     $this->view->assetsPackage = Kwf_Assets_Package_Maintenance::getInstance('Maintenance');
     $this->view->xtype = 'kwf.maintenance.update';
     $this->view->useBackgroundProcess = !!Kwf_Config::getValue('server.phpCli');
 }
 public static function restoreMaintenanceBootstrapSelf($output = true)
 {
     if (!file_exists('bootstrap.php.backup')) {
         throw new Kwf_Exception("maintenance bootstrap not written");
     }
     unlink('bootstrap.php');
     rename('bootstrap.php.backup', 'bootstrap.php');
     if ($output) {
         echo "\nrestored bootstrap.php\n";
     }
     Kwf_Util_ClearCache::clearOptcode(getcwd() . '/bootstrap.php');
 }
 public function jsonClearCacheAction()
 {
     $type = $this->_getParam('type');
     $cc = Kwf_Util_ClearCache::getInstance();
     if ($type == 'media') {
         $cc->clearCache(array('types' => 'media', 'output' => false, 'refresh' => true));
     } else {
         if ($type == 'assets') {
             $cc->clearCache(array('types' => 'assets', 'output' => false, 'refresh' => true));
         } else {
             if ($type == 'trl') {
                 $cache = new Kwf_Util_ClearCache_Types_Trl();
                 $cache->clearCache(array());
             }
         }
     }
 }
 public static function clearCache($request, $view)
 {
     $options = array();
     if ($request->getParam('skip-other-servers')) {
         $options['skipOtherServers'] = true;
     }
     $c = new Kwf_Util_ProgressBar_Adapter_Cache($request->getParam('progressNum'));
     $options['progressAdapter'] = $c;
     $options['types'] = $request->getParam('type');
     $options['output'] = false;
     $options['refresh'] = true;
     $types = Kwf_Util_ClearCache::getInstance()->clearCache($options);
     $message = '';
     foreach ($types as $t) {
         if (!$t->getSuccess()) {
             $message .= $t->getTypeName() . " ERROR: " . $t->getOutput();
         }
     }
     $view->success = true;
     $view->message = $message;
 }
 public function indexAction()
 {
     Kwf_Util_MemoryLimit::set(512);
     Kwf_Events_ModelObserver::getInstance()->disable();
     //try to update old-style db config
     if (file_exists('config.db.ini')) {
         $db = file_get_contents('config.db.ini');
         if (file_exists('config.local.ini')) {
             $c = file_get_contents('config.local.ini');
         } else {
             $c = "[production]\n";
         }
         $c .= "\n";
         $db = str_replace("[database]\n", '', $db);
         foreach (explode("\n", trim($db)) as $line) {
             if (trim($line)) {
                 $c .= "database." . $line . "\n";
             }
         }
         file_put_contents('config.local.ini', $c);
         unlink('config.db.ini');
     }
     if ($this->_getParam('rev')) {
         throw new Kwf_Exception("rev parameter is not supported anymore");
     }
     if ($this->_getParam('class')) {
         throw new Kwf_Exception("class parameter is not supported anymore");
     }
     $skipClearCache = $this->_getParam('skip-clear-cache');
     $doneNames = Kwf_Util_Update_Helper::getExecutedUpdatesNames();
     if ($this->_getParam('name')) {
         $updates = Kwf_Util_Update_Helper::getUpdates();
         foreach ($updates as $k => $u) {
             $n = $u->getUniqueName();
             $n = substr($n, strrpos($n, '_') + 1);
             if ($n != $this->_getParam('name')) {
                 unset($updates[$k]);
             }
         }
     } else {
         if (!$skipClearCache) {
             Kwf_Util_ClearCache::getInstance()->clearCache(array('types' => 'all', 'output' => true, 'refresh' => false));
         }
         echo "Looking for update-scripts...";
         $updates = Kwf_Util_Update_Helper::getUpdates();
         foreach ($updates as $k => $u) {
             if (in_array($u->getUniqueName(), $doneNames) || $u->getLegacyName() && in_array($u->getLegacyName(), $doneNames)) {
                 unset($updates[$k]);
             }
         }
         echo " found " . count($updates) . "\n\n";
     }
     if (!$this->_getParam('debug')) {
         Kwf_Util_Maintenance::writeMaintenanceBootstrap();
     }
     $c = new Zend_ProgressBar_Adapter_Console();
     $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
     $c->setTextWidth(50);
     $runner = new Kwf_Util_Update_Runner($updates);
     $progress = new Zend_ProgressBar($c, 0, $runner->getProgressSteps());
     $runner->setProgressBar($progress);
     $runner->setVerbose(true);
     $runner->setEnableDebug($this->_getParam('debug'));
     $runner->setSkipClearCache($skipClearCache);
     if (!$runner->checkUpdatesSettings()) {
         echo "\ncheckSettings failed, update stopped\n";
     } else {
         $executedUpdates = $runner->executeUpdates();
         echo "\nupdate finished\n";
         $doneNames = array_unique(array_merge($doneNames, $executedUpdates));
         $runner->writeExecutedUpdates($doneNames);
     }
     if (!$this->_getParam('debug')) {
         Kwf_Util_Maintenance::restoreMaintenanceBootstrap();
     }
     $errors = $runner->getErrors();
     if ($errors) {
         echo "\n\n" . str_repeat('=', 16) . "\n";
         echo count($errors) . " update script(s) failed:\n";
         foreach ($errors as $error) {
             echo $error['name'] . ": \n";
             echo $error['message'] . "\n\n";
         }
         exit(1);
     } else {
         echo "\n" . count($updates) . " update script(s) successfully executed.\n";
         exit(0);
     }
 }
 public function indexAction()
 {
     $this->view->typeNames = Kwf_Util_ClearCache::getInstance()->getTypeNames();
     $this->view->assetsPackage = Kwf_Assets_Package_Maintenance::getInstance('Maintenance');
     $this->view->xtype = 'kwf.maintenance.fulltext';
 }
Пример #9
0
 public function executeUpdates($options = array())
 {
     $doneNames = array();
     $this->_executeUpdatesAction('preUpdate');
     $this->_executeUpdatesAction('update');
     if ($this->_progressBar) {
         $this->_progressBar->finish();
     }
     $this->_executeUpdatesAction('postUpdate');
     if (!$this->_skipClearCache) {
         if ($this->_verbose) {
             echo "\n";
         }
         Kwf_Util_ClearCache::getInstance()->clearCache(array('types' => 'all', 'excludeTypes' => $this->_excludeClearCacheTypes, 'output' => $this->_verbose, 'refresh' => isset($options['refreshCache']) ? $options['refreshCache'] : true));
         if ($this->_verbose) {
             echo "\n";
         }
     }
     $this->_executeUpdatesAction('postClearCache');
     foreach ($this->_updates as $k => $u) {
         $doneNames[] = $u->getUniqueName();
     }
     return $doneNames;
 }
 public static function getHelpOptions()
 {
     $types = array();
     foreach (Kwf_Util_ClearCache::getInstance()->getTypes() as $t) {
         $types[] = $t->getTypeName();
     }
     return array(array('param' => 'type', 'value' => implode(',', $types), 'valueOptional' => true, 'help' => 'what to clear'));
 }
Пример #11
0
 protected function _clearCache($options)
 {
     Kwf_Util_ClearCache::clearApcUser();
 }
Пример #12
0
 protected function _clearCache($options)
 {
     Kwf_Util_ClearCache::clearOptcode();
 }
Пример #13
0
 protected function _refreshCache($options)
 {
     $file = 'cache/setup' . Kwf_Setup::CACHE_SETUP_VERSION . '.php';
     file_put_contents($file, Kwf_Util_Setup::generateCode(Kwf_Setup::$configClass));
     Kwf_Util_ClearCache::clearOptcode(getcwd() . '/' . $file);
 }
 public static function downloadUpdates($request, $view)
 {
     $urls = array();
     if ($request->getParam('libraryUrl')) {
         $urls['library.tar.gz'] = $request->getParam('libraryUrl');
     }
     $urls['kwf.tar.gz'] = $request->getParam('kwfUrl');
     $urls['app.tar.gz'] = $request->getParam('appUrl');
     $c = new Kwf_Util_ProgressBar_Adapter_Cache($request->getParam('progressNum'));
     $progress = new Zend_ProgressBar($c, 0, 6);
     foreach ($urls as $target => $url) {
         $progress->next(1, 'Downloading ' . $target);
         exec("wget -O " . escapeshellarg($target) . " " . escapeshellarg($url) . " 2>&1", $out, $ret);
         if ($ret) {
             throw new Kwf_Exception_Client("Download Failed:" . implode("\n", $out));
         }
     }
     foreach ($urls as $target => $url) {
         $progress->next(1, 'Extracting ' . $target);
         $dir = tempnam('.', 'downloader');
         unlink($dir);
         mkdir($dir);
         exec("tar xfz {$target} -C {$dir}" . " 2>&1", $out, $ret);
         if ($ret) {
             throw new Kwf_Exception_Client("Extraction failed");
         }
         $dirs = glob("{$dir}/*");
         if (count($dirs) != 1) {
             throw new Kwf_Exception_Client("more than one directory extracted");
         }
         if (!is_dir($dirs[0])) {
             throw new Kwf_Exception_Client("no directory extracted");
         }
         if ($target == 'app.tar.gz') {
             //move away current files to backup
             $backupDir = uniqid("backup" . date('Y-m-d')) . 'app';
             mkdir($backupDir);
             $it = new DirectoryIterator(getcwd());
             foreach ($it as $file) {
                 if ($file->isDot()) {
                     continue;
                 }
                 if (substr($file->getFilename(), -4) == '-lib' || $file->getFilename() == 'library') {
                     continue;
                 }
                 if (substr($file->getFilename(), 0, 6) == 'backup') {
                     continue;
                 }
                 if ($file->getFilename() == 'config.local.ini') {
                     continue;
                 }
                 if ($file->getFilename() == 'config_section') {
                     continue;
                 }
                 if ($file->getFilename() == 'php.ini') {
                     continue;
                 }
                 //php config might be in document_root (wtf, godaddy)
                 if ($file->getFilename() == 'php5.ini') {
                     continue;
                 }
                 //php config might be in document_root (wtf, godaddy)
                 if ($file->getFilename() == $backupDir) {
                     continue;
                 }
                 if ($file->getPathname() == $dir) {
                     continue;
                 }
                 if ($file->getFilename() == 'app.tar.gz') {
                     continue;
                 }
                 if ($file->getFilename() == 'temp') {
                     continue;
                 }
                 if ($file->getFilename() == 'log') {
                     continue;
                 }
                 if ($file->getFilename() == 'uploads') {
                     continue;
                 }
                 rename($file->getPathname(), $backupDir . '/' . $file->getFilename());
             }
             //move in new files
             $it = new DirectoryIterator($dirs[0]);
             foreach ($it as $file) {
                 if ($file->isDot()) {
                     continue;
                 }
                 if ($file->getFilename() == 'temp') {
                     continue;
                 }
                 if ($file->getFilename() == 'log') {
                     continue;
                 }
                 if ($file->getFilename() == 'uploads') {
                     continue;
                 }
                 rename($file->getPathname(), './' . $file->getFilename());
             }
             system("rm -r " . escapeshellarg($dirs[0]));
             $oldHtaccess = file_get_contents($backupDir . '/.htaccess');
             if (!strpos('php_flag magic_quotes_gpc off', $oldHtaccess)) {
                 $c = file_get_contents('.htaccess');
                 $c = str_replace('php_flag magic_quotes_gpc off', '', $c);
                 file_put_contents('.htaccess', $c);
             }
         } else {
             $targetDir = false;
             if ($target == 'library.tar.gz') {
                 $targetDir = 'library';
             } else {
                 if ($target == 'kwf.tar.gz') {
                     $targetDir = 'kwf-lib';
                     copy($targetDir . '/include_path', $dirs[0] . '/include_path');
                 }
             }
             rename($targetDir, uniqid("backup" . date('Y-m-d')) . $targetDir);
             rename("{$dirs['0']}", $targetDir);
         }
         rmdir($dir);
         unlink($target);
     }
     Kwf_Util_ClearCache::getInstance()->clearCache(array('types' => 'all', 'output' => false, 'refresh' => true));
 }