/** * Runs the update query to apply the change to the database * * @return void * * @since 2.5 */ public function fix() { if ($this->checkStatus === -2) { // At this point we have a failed query $query = $this->db->convertUtf8mb4QueryToUtf8($this->updateQuery); $this->db->setQuery($query); if ($this->db->execute()) { if ($this->check()) { $this->checkStatus = 1; $this->rerunStatus = 1; } else { $this->rerunStatus = -2; } } else { $this->rerunStatus = -2; } } }
/** * Method to import a database schema from a file. * * @param JDatabaseDriver $db JDatabase object. * @param string $schema Path to the schema file. * * @return boolean True on success. * * @since 3.1 */ public function populateDatabase($db, $schema) { // Get the application /* @var InstallationApplicationWeb $app */ $app = JFactory::getApplication(); $return = true; // Get the contents of the schema file. if (!($buffer = file_get_contents($schema))) { $app->enqueueMessage($db->getErrorMsg(), 'notice'); return false; } // Get an array of queries from the schema and process them. $queries = $this->_splitQueries($buffer); foreach ($queries as $query) { // Trim any whitespace. $query = trim($query); // If the query isn't empty and is not a MySQL or PostgreSQL comment, execute it. if (!empty($query) && $query[0] != '#' && $query[0] != '-') { /** * If we don't have UTF-8 Multibyte support we'll have to convert queries to plain UTF-8 * * Note: the JDatabaseDriver::convertUtf8mb4QueryToUtf8 performs the conversion ONLY when * necessary, so there's no need to check the conditions in JInstaller. */ $query = $db->convertUtf8mb4QueryToUtf8($query); /** * This is a query which was supposed to convert tables to utf8mb4 charset but the server doesn't * support utf8mb4. Therefore we don't have to run it, it has no effect and it's a mere waste of time. */ if (!$db->hasUTF8mb4Support() && stristr($query, 'CONVERT TO CHARACTER SET utf8 ')) { continue; } // Execute the query. $db->setQuery($query); try { $db->execute(); } catch (RuntimeException $e) { $app->enqueueMessage($e->getMessage(), 'notice'); $return = false; } } } return $return; }