reset() public static method

public static reset ( ) : Zend_Db_Adapter_Abstract
return Zend_Db_Adapter_Abstract
Beispiel #1
0
 /**
  * @param $file
  * @throws \Zend_Db_Adapter_Exception
  */
 public function insertDump($file)
 {
     $sql = file_get_contents($file);
     //replace document root placeholder with current document root
     $docRoot = str_replace("\\", "/", PIMCORE_DOCUMENT_ROOT);
     // Windows fix
     $sql = str_replace("~~DOCUMENTROOT~~", $docRoot, $sql);
     // we have to use the raw connection here otherwise \Zend_Db uses prepared statements, which causes problems with inserts (: placeholders)
     // and mysqli causes troubles because it doesn't support multiple queries
     if ($this->db->getResource() instanceof \Zend_Db_Adapter_Mysqli) {
         $mysqli = $this->db->getConnection();
         $mysqli->multi_query($sql);
         // loop through results, because ->multi_query() is asynchronous
         do {
             if ($result = $mysqli->store_result()) {
                 $mysqli->free_result();
             }
         } while ($mysqli->next_result());
     } elseif ($this->db->getResource() instanceof \Zend_Db_Adapter_Pdo_Mysql) {
         $this->db->getConnection()->exec($sql);
     }
     \Pimcore\Db::reset();
     // set the id of the system user to 0
     $this->db->update("users", ["id" => 0], $this->db->quoteInto("name = ?", "system"));
 }
Beispiel #2
0
 /**
  * @param $name
  * @param $type
  * @return array
  */
 public function mysqlData($name, $type)
 {
     $db = Db::reset();
     $dumpData = "\n\n";
     $name = $db->quoteTableAs($name);
     if ($type != "VIEW") {
         // backup tables
         $tableData = $db->fetchAll("SELECT * FROM " . $name);
         foreach ($tableData as $row) {
             $cells = array();
             foreach ($row as $cell) {
                 if (is_string($cell)) {
                     $cell = $db->quote($cell);
                 } else {
                     if ($cell === null) {
                         $cell = "NULL";
                     }
                 }
                 $cells[] = $cell;
             }
             $dumpData .= "INSERT INTO " . $name . " VALUES (" . implode(",", $cells) . ");";
             $dumpData .= "\n";
         }
     } else {
         // dump view structure
         $dumpData .= "\n\n";
         $dumpData .= "DROP VIEW IF EXISTS " . $name . ";";
         $dumpData .= "\n";
         try {
             $viewData = $db->fetchRow("SHOW CREATE VIEW " . $name);
             $dumpData .= $viewData["Create View"] . ";";
         } catch (\Exception $e) {
             \Logger::error($e);
         }
     }
     $dumpData .= "\n\n";
     $h = fopen(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/backup-dump.sql", "a+");
     fwrite($h, $dumpData);
     fclose($h);
     return array("success" => true);
 }
Beispiel #3
0
 /**
  * Forces a garbage collection.
  * @static
  * @return void
  */
 public static function collectGarbage($keepItems = array())
 {
     // close mysql-connection
     Db::close();
     $protectedItems = array("Zend_Locale", "Zend_View_Helper_Placeholder_Registry", "Zend_View_Helper_Doctype", "Zend_Translate", "Zend_Navigation", "Pimcore_API_Plugin_Broker", "pimcore_tag_block_current", "pimcore_tag_block_numeration", "Config_system", "pimcore_admin_user", "Config_website", "pimcore_editmode", "pimcore_error_document", "pimcore_site", "Pimcore_Db");
     if (is_array($keepItems) && count($keepItems) > 0) {
         $protectedItems = array_merge($protectedItems, $keepItems);
     }
     if (is_array(self::$globallyProtectedItems) && count(self::$globallyProtectedItems)) {
         $protectedItems = array_merge($protectedItems, self::$globallyProtectedItems);
     }
     $registryBackup = array();
     foreach ($protectedItems as $item) {
         if (\Zend_Registry::isRegistered($item)) {
             $registryBackup[$item] = \Zend_Registry::get($item);
         }
     }
     \Zend_Registry::_unsetInstance();
     foreach ($registryBackup as $key => $value) {
         \Zend_Registry::set($key, $value);
     }
     Db::reset();
     // force PHP garbage collector
     gc_enable();
     $collectedCycles = gc_collect_cycles();
     \Logger::debug("garbage collection finished, collected cycles: " . $collectedCycles);
 }
Beispiel #4
0
 /**
  * @param $job
  * @return bool
  */
 protected function launchJob($job)
 {
     $pid = pcntl_fork();
     if ($pid == -1) {
         //Problem launching the job
         \Logger::error('Could not launch new job with id [ ' . $job->getId() . ' ], exiting');
         return false;
     } else {
         if ($pid) {
             $this->currentJobs[$pid] = $job->getId();
             if (isset($this->signalQueue[$pid])) {
                 $this->childSignalHandler(SIGCHLD, $pid, $this->signalQueue[$pid]);
                 unset($this->signalQueue[$pid]);
             }
         } else {
             //Forked child
             try {
                 \Pimcore\Db::reset();
                 // reset resource
                 \Pimcore::initLogger();
                 // reinit logger so that he gets a different token eg for mailing
                 \Logger::debug("Executing job [ " . $job->getId() . " ] as forked child");
                 $job->execute();
             } catch (\Exception $e) {
                 \Logger::error($e);
                 \Logger::error("Failed to execute job with id [ " . $job->getId() . " ] and method [ " . $job->getMethod() . " ]");
             }
             $job->unlock();
             \Logger::debug("Done with job [ " . $job->getId() . " ]");
             exit(0);
         }
     }
     return true;
 }