Example #1
0
 /**
  * Preprocessor for no-action ren
  *
  * @return void
  */
 protected function doNoAction()
 {
     \Includes\Utils\Operator::flush($this->getInfoMessage());
     exit(0);
 }
Example #2
0
 /**
  * Show log file content
  *
  * @return void
  */
 protected function doActionViewLogFile()
 {
     $path = \XLite\Upgrade\Logger::getInstance()->getLastLogFile();
     if ($path) {
         header('Content-Type: text/plain', true);
         \Includes\Utils\Operator::flush(\Includes\Utils\FileManager::read($path));
         exit(0);
     } else {
         \XLite\Core\TopMessage::addWarning('Log files not found');
     }
 }
Example #3
0
 /**
  * Echo chunk
  *
  * @param string &$chunk Text chunk to output
  *
  * @return void
  */
 protected function echoChunk(&$chunk)
 {
     \Includes\Utils\Operator::flush($chunk, false, null);
 }
Example #4
0
 /**
  * Common restore database method used by actions
  *
  * @param mixed $sqlFile File with SQL data for loading into database
  *
  * @return boolean
  */
 protected function restoreDatabase($sqlFile)
 {
     $result = false;
     // File to create temporary backup to be able rollback database
     $backupSQLFile = LC_DIR_BACKUP . sprintf('sqldump.backup.%d.sql', \XLite\Core\Converter::time());
     // Make the process of restoring database verbose
     $verbose = true;
     // Start
     $this->startDump();
     // Making the temporary backup file
     \Includes\Utils\Operator::flush(static::t('Making backup of the current database state ... '), true);
     $result = \XLite\Core\Database::getInstance()->exportSQLToFile($backupSQLFile, $verbose);
     \Includes\Utils\Operator::flush(static::t('done') . LC_EOL . LC_EOL, true);
     // Loading specified SQL-file to the database
     \Includes\Utils\Operator::flush(static::t('Loading the database from file .'));
     $result = \Includes\Utils\Database::uploadSQLFromFile($sqlFile, $verbose);
     $restore = false;
     if ($result) {
         // If file has been loaded into database successfully
         $message = static::t('Database restored successfully!');
         // Prepare the cache rebuilding
         \XLite::setCleanUpCacheFlag(true);
     } else {
         // If an error occured while loading file into database
         $message = static::t('The database has not been restored because of the errors');
         $restore = true;
     }
     // Display the result message
     \Includes\Utils\Operator::flush(' ' . static::t('done') . LC_EOL . LC_EOL . $message . LC_EOL);
     if ($restore) {
         // Restore database from temporary backup
         \Includes\Utils\Operator::flush(LC_EOL . static::t('Restoring database from the backup .'));
         \Includes\Utils\Database::uploadSQLFromFile($backupSQLFile, $verbose);
         \Includes\Utils\Operator::flush(' ' . static::t('done') . LC_EOL . LC_EOL);
     }
     // Display Javascript to cancel scrolling page to bottom
     func_refresh_end();
     // Display the bottom HTML part
     $this->displayPageFooter();
     // Remove temporary backup file
     unlink($backupSQLFile);
     return $result;
 }
Example #5
0
 /**
  * Process request
  *
  * @return void
  */
 public function processRequest()
 {
     header('Content-Type: text/html; charset=utf-8');
     \Includes\Utils\Operator::flush($this->getJSONData());
 }
Example #6
0
 /**
  * Execute a set of SQL queries from file
  *
  * :FIXME: must be completely revised
  *
  * @param string  $fileName Name of SQL-file
  * @param boolean $verbose  Display uploading progress flag OPTIONAL
  *
  * @return boolean
  */
 public static function uploadSQLFromFile($fileName, $verbose = false)
 {
     $result = false;
     if (false == \Includes\Utils\FileManager::isFileReadable($fileName)) {
         throw new \InvalidArgumentException(sprintf('SQL file \'%s\' not found or is not readable', $fileName));
     } else {
         $fp = fopen($fileName, 'rb');
         $sql = '';
         $result = true;
         static::exec('SET NAMES utf8');
         while ($result && !feof($fp)) {
             $c = '';
             // Read SQL statement from file
             do {
                 $c .= fgets($fp, 1024);
                 $endPos = strlen($c) - 1;
             } while (substr($c, $endPos) != PHP_EOL && !feof($fp));
             $c = rtrim($c);
             // Skip comments
             if (substr($c, 0, 1) == '#' || substr($c, 0, 2) == '--') {
                 continue;
             }
             // Parse SQL statement
             $sql .= $c;
             if (substr($sql, -1) == ';') {
                 $sql = substr($sql, 0, strlen($sql) - 1);
                 $sql = str_replace(static::TABLE_PREFIX_PLACEHOLDER, static::getTablesPrefix(), $sql);
                 // Execute SQL query
                 try {
                     static::getHandler()->beginTransaction();
                     $result = false !== static::exec($sql);
                     if ($result) {
                         static::getHandler()->commit();
                     } else {
                         static::getHandler()->rollBack();
                     }
                     if ($verbose) {
                         \Includes\Utils\Operator::flush('.');
                     }
                 } catch (\PDOException $e) {
                     static::getHandler()->rollBack();
                     $result = false;
                     \Includes\Utils\Operator::flush(LC_EOL . $e->getMessage());
                 }
                 $sql = '';
             }
         }
         fclose($fp);
     }
     return $result;
 }