/** * Fix schema version if wrong * * @param JSchemaChangeSet $changeSet Schema change set * * @return mixed string schema version if success, false if fail */ public function fixSchemaVersion($changeSet) { // Get correct schema version -- last file in array $schema = $changeSet->getSchema(); $db = JFactory::getDbo(); $result = false; // Check value. If ok, don't do update $version = $this->getSchemaVersion(); if ($version == $schema) { $result = $version; } else { // Delete old row $query = $db->getQuery(true) ->delete($db->quoteName('#__schemas')) ->where($db->quoteName('extension_id') . ' = 700'); $db->setQuery($query); $db->execute(); // Add new row $query = $db->getQuery(true) ->insert($db->quoteName('#__schemas')) ->set($db->quoteName('extension_id') . '= 700') ->set($db->quoteName('version_id') . '= ' . $db->quote($schema)); $db->setQuery($query); if ($db->execute()) { $result = $schema; } } return $result; }
/** * Fix schema version if wrong. * * @param JSchemaChangeSet $changeSet Schema change set. * * @return mixed string schema version if success, false if fail. */ public function fixSchemaVersion($changeSet) { // Get correct schema version -- last file in array. $schema = $changeSet->getSchema(); // Check value. If ok, don't do update. if ($schema == $this->getSchemaVersion()) { return $schema; } // Delete old row. $db = $this->getDbo(); $query = $db->getQuery(true)->delete($db->quoteName('#__schemas'))->where($db->quoteName('extension_id') . ' = 700'); $db->setQuery($query); $db->execute(); // Add new row. $query->clear()->insert($db->quoteName('#__schemas'))->columns($db->quoteName('extension_id') . ',' . $db->quoteName('version_id'))->values('700, ' . $db->quote($schema)); $db->setQuery($query); try { $db->execute(); } catch (JDatabaseExceptionExecuting $e) { return false; } return $schema; }