/** * Returns database dump data * * @return array */ public function getDumpChecksum() { if (is_null($this->_aDBDump)) { modConfig::getInstance()->cleanup(); modConfig::$unitMOD = null; $aDBDump = file_get_contents($this->getDumpFolderPath() . 'dbdata'); $this->_aDBDump = unserialize($aDBDump); } return $this->_aDBDump; }
/** * Returns array of available currencies * * @param integer $iCurrency Active currency number (default null) * * @return array */ public function getCurrencyArray($iCurrency = null) { $aConfCurrencies = $this->getConfigParam('aCurrencies'); if (!is_array($aConfCurrencies)) { return array(); } if (defined('OXID_PHP_UNIT')) { if (isset(modConfig::$unitMOD) && is_object(modConfig::$unitMOD)) { try { $aAltCurrencies = modConfig::getInstance()->getConfigParam('modaCurrencies'); if (isset($aAltCurrencies)) { $aConfCurrencies = $aAltCurrencies; } } catch (Exception $e) { // if exception is thrown, use default } } } // processing currency configuration data $aCurrencies = array(); reset($aConfCurrencies); while (list($key, $val) = each($aConfCurrencies)) { if ($val) { $oCur = new oxStdClass(); $oCur->id = $key; $sCur = explode('@', $val); $oCur->name = trim($sCur[0]); $oCur->rate = trim($sCur[1]); $oCur->dec = trim($sCur[2]); $oCur->thousand = trim($sCur[3]); $oCur->sign = trim($sCur[4]); $oCur->decimal = trim($sCur[5]); // change for US version if (isset($sCur[6])) { $oCur->side = trim($sCur[6]); } if (isset($iCurrency) && $key == $iCurrency) { $oCur->selected = 1; } else { $oCur->selected = 0; } $aCurrencies[$key] = $oCur; } // #861C - performance, do not load other currencies if (!$this->getConfigParam('bl_perfLoadCurrency')) { break; } } return $aCurrencies; }
public static function getConfig() { return modConfig::getInstance(); }
public static function _appendToChain($aExtend) { // if the chain is still empty and "original" chain is needed if (self::$_blOriginal && !count(self::$_aChain)) { self::$_aChain = (array) modConfig::getInstance()->getConfigParam("aModules"); } // addping the "extend" chain to the main chain foreach ($aExtend as $sParent => $sExtends) { if (isset(self::$_aChain[$sParent])) { $sExtends = trim(self::$_aChain[$sParent], "& ") . "&" . trim($sExtends, "& "); } self::$_aChain[$sParent] = $sExtends; } }
/** * Converts a string to UTF format. * * @todo move to separate class instead of static * * @return array */ protected static function getDbChecksum() { $myDB = oxDb::getDB(); $myConfig = modConfig::getInstance(); $sSelect = 'select GROUP_CONCAT(DISTINCT t.TABLE_NAME) from INFORMATION_SCHEMA.tables as t where t.TABLE_SCHEMA = "' . $myConfig->getConfigParam('dbName') . '" and t.TABLE_NAME not like "oxv_%"'; $rs = $myDB->execute($sSelect); $sSelect = 'CHECKSUM TABLE ' . $rs->fields[0]; $rs = $myDB->execute($sSelect); if ($rs != false && $rs->RecordCount() > 0) { while (!$rs->EOF) { if (stripos($rs->fields[0], "oxv_") !== 0) { $aChecksum[$rs->fields[0]] = $rs->fields[1]; } $rs->MoveNext(); } } return $aChecksum; }
public function cleanup() { modConfig::getInstance()->remClassFunction('getDB'); self::$unitMOD = null; parent::cleanup(); }
/** * Checks which tables of the db changed and then restores these tables. * * Uses dump file '/tmp/tmp_db_dump' for comparison and restoring. * * @param integer $iMode Maintenance mode * @param integer $iOutput Outout type * * @return integer changet */ public function restoreDB($iMode = MAINTENANCE_SINGLEROWS, $iOutput = MAINTENANCE_MODE_ONLYRESET) { // php 523 error modConfig::getInstance()->cleanup(); modConfig::$unitMOD = null; $time = microtime(true); $myConfig = oxConfig::getInstance(); $sDbName = oxConfig::getInstance()->getConfigParam('dbName'); $this->_oDBDump = file_get_contents('/tmp/tmp_db_dump_' . $sDbName); $this->_oDBDump = unserialize($this->_oDBDump); $myDB = oxDb::getDb(); $myDB->SetFetchMode(ADODB_FETCH_NUM); $rs = $myDB->Query("SHOW TABLES"); $myDB->SetFetchMode(ADODB_FETCH_ASSOC); $sChanges = ""; //current table $sTable = ""; //list of sql commands to execute; $aSQL = array(); $aInsert = array(); $aTableInsert = array(); while (!$rs->EOF) { $sTable = $rs->fields[0]; $rs->moveNext(); if (strpos($sTable, "oxv_") === false) { $aChangesCounter[$sTable] = 0; if (!isset($this->_oDBDump[$sTable])) { $sChanges .= "Table " . $sTable . " was added\n"; $aChangesCounter[$sTable]++; //delete this table $aSQL[] = "DROP TABLE " . $sTable . ""; continue; } $rs2 = $myDB->Query("Select * from " . $sTable); if ($rs2 && $rs2->RecordCount() > 0) { $rowCount = 1; while ($aRow = $rs2->fetchRow()) { $oxid = $aRow['OXID']; $blNoOXID = false; if ($oxid == "") { // the tables without oxid, $oxid = $rowCount++; $blNoOXID = true; } if (!isset($this->_oDBDump[$sTable][$oxid])) { $aChangesCounter[$sTable]++; if ($iMode == MAINTENANCE_SINGLEROWS && !$blNoOXID) { $sChanges .= "In table " . $sTable . " a record was added\n"; $aSQL[] = "DELETE FROM " . $sTable . " WHERE OXID = '" . $oxid . "'"; $aInsert[$sTable][] = $oxid; //mark this row as existing $this->_oDBDump[$sTable][$oxid]['_EXISTS_'] = true; continue; //with next row } else { if ($iMode == MAINTENANCE_WHOLETABLES || $blNoOXID) { //in single table mode tables without oxid are handeld like in whole table mode $sChanges .= "In table " . $sTable . " record(s)was(were) added\n"; $aSQL[] = "DELETE FROM " . $sTable; $aTableInsert[] = $sTable; //mark this table as existing $this->_oDBDump[$sTable]['_EXISTS_'] = true; //skip rest of table continue 2; } } } else { //check only if the record already existed foreach ($aRow as $sColumn => $sEntry) { if ($sColumn == "OXVARVALUE") { //special handeling of blob values of oxconfig $sEntry = oxUtils::getInstance()->strMan($sEntry, $myConfig->getConfigParam('sConfigKey')); } if (!isset($this->_oDBDump[$sTable][$oxid][$sColumn])) { //a new colum $aChangesCounter[$sTable]++; if ($iMode == MAINTENANCE_SINGLEROWS && !$blNoOXID) { $sChanges .= "In table " . $sTable . " and record oxid: " . $oxid . " column " . $sColumn . " was added\n"; $aSQL[] = "DELETE FROM " . $sTable . " WHERE OXID = '" . $oxid . "'"; $aInsert[$sTable][] = $oxid; //mark this row as existing $this->_oDBDump[$sTable][$oxid]['_EXISTS_'] = true; //skip rest of row continue 2; } else { if ($iMode == MAINTENANCE_WHOLETABLES || $blNoOXID) { $sChanges .= "In table " . $sTable . " column(s) {$sColumn} was(were) added\n"; $aSQL[] = "DELETE FROM " . $sTable; $aTableInsert[] = $sTable; //mark this table as existing $this->_oDBDump[$sTable]['_EXISTS_'] = true; //skip rest of table continue 3; } } } elseif (strcmp($this->_oDBDump[$sTable][$oxid][$sColumn], $sEntry) != 0) { //changed value $aChangesCounter[$sTable]++; if ($iMode == MAINTENANCE_SINGLEROWS && !$blNoOXID) { $sChanges .= "In table " . $sTable . ", record oxid: " . $oxid . " and column " . $sColumn . " the value changed from: " . $this->_oDBDump[$sTable][$oxid][$sColumn] . " to: " . $sEntry . "\n"; $aSQL[] = "DELETE FROM " . $sTable . " WHERE OXID = '" . $oxid . "'"; $aInsert[$sTable][] = $oxid; //mark this row as existing $this->_oDBDump[$sTable][$oxid]['_EXISTS_'] = true; //skip rest of row continue 2; } elseif ($iMode == MAINTENANCE_WHOLETABLES || $blNoOXID) { $sChanges .= "In table " . $sTable . ", record values changed\n"; $aSQL[] = "DELETE FROM " . $sTable; $aTableInsert[] = $sTable; //mark this table as existing $this->_oDBDump[$sTable]['_EXISTS_'] = true; //skip rest of table continue 3; } } } } $this->_oDBDump[$sTable][$oxid]['_EXISTS_'] = true; } } //checking for removed rows foreach ($this->_oDBDump[$sTable] as $oxid => $aEntry) { if ($oxid == '_EXISTS_') { if ($iMode == MAINTENANCE_WHOLETABLES) { //everything is fine, whole table will be inserted continue; } } else { if (!isset($aEntry['_EXISTS_'])) { $sChanges .= "In table " . $sTable . ", record oxid " . $oxid . " was removed (" . $aEntry . ")\n"; $aChangesCounter[$sTable]++; //add the record again, same for both modes $aInsert[$sTable][] = $oxid; } } } } } //add the restore sql scripts foreach ($aInsert as $sTable => $aOxid) { foreach ($aOxid as $k => $oxid) { $aSQL[] = $this->_oDBDump[$sTable][$oxid]["_sql_"]; } } //add the whole tables (for MAINTENANCE_WHOLETABLES mode) foreach ($aTableInsert as $k => $sTable) { foreach ($this->_oDBDump[$sTable] as $oxid => $aVals) { if ($oxid == '_EXISTS_') { continue; } $aSQL[] = $aVals["_sql_"]; } } if ($iOutput == MAINTENANCE_MODE_ONLYOUTPUT || $iOutput == MAINTENANCE_MODE_RESETANDOUTPUT) { $sChanges .= "\n\n"; $sChanges .= "DB RESET EXECUTION. start time: " . date('Y-m-d H:i:s'); $sChanges .= "\n"; $i = 0; foreach ($aChangesCounter as $sTable => $iChanges) { if ($iChanges > 0) { $sChanges .= "In table " . $sTable . " are " . $iChanges . " changes!\n"; $i += $iChanges; } } $sChanges .= "\nIn total there are " . $i . " changes!!!\n\n\n\n"; if ($i > 0) { file_put_contents('dbchanges_log.txt', $sChanges . var_export($aSQL, 1) . var_export($this->_oDBDump, 1), FILE_APPEND); } } if ($iOutput == MAINTENANCE_MODE_ONLYRESET || $iOutput == MAINTENANCE_MODE_RESETANDOUTPUT) { //now execute delete and drop statements and the insert statements (at the end) foreach ($aSQL as $k => $v) { $myDB->Query($v); } } $myDB->SetFetchMode(ADODB_FETCH_NUM); //echo(" T:".(microtime(true)-$time)); return $aChangesCounter; }
public function testBackupToFile() { // Config mock $oConfig = $this->getMock('oxConfig', array('getVersion', 'getEdition', 'getShopId')); $oConfig->expects($this->once())->method('getVersion')->will($this->returnValue('5.1.0')); $oConfig->expects($this->once())->method('getEdition')->will($this->returnValue('EE')); $oConfig->expects($this->once())->method('getShopId')->will($this->returnValue(1)); modConfig::getInstance()->setConfigParam('sShopDir', '/var/www/my_shop/'); // Configuration storage mock $oConfigStorage = $this->getMock('oxpsModulesConfigStorage', array('__call', 'load')); $oConfigStorage->expects($this->at(0))->method('load')->with('mymodule', 'version')->will($this->returnValue('1.1.0')); $oConfigStorage->expects($this->at(1))->method('load')->with('mymodule', 'extend')->will($this->returnValue(array())); $oConfigStorage->expects($this->at(2))->method('load')->with('mymodule', 'files')->will($this->returnValue(array('mymoduleitem' => 'my/module/models/mymoduleitem.php'))); $oConfigStorage->expects($this->at(3))->method('load')->with('othermodule', 'version')->will($this->returnValue('0.1.0')); $oConfigStorage->expects($this->at(4))->method('load')->with('othermodule', 'extend')->will($this->returnValue(array('basket' => 'other/module/controllers/othermodulebasket', 'oxarticle' => 'other/module/models/othermoduleoxarticle'))); $oConfigStorage->expects($this->at(5))->method('load')->with('othermodule', 'files')->will($this->returnValue(array())); oxRegistry::set('oxpsModulesConfigStorage', $oConfigStorage); $this->SUT->expects($this->exactly(2))->method('getConfig')->will($this->returnValue($oConfig)); $this->SUT->expects($this->never())->method('_jsonDownload'); $this->SUT->expects($this->once())->method('_touchBackupsDir')->with('/var/www/my_shop/export/modules_config/'); $this->SUT->expects($this->once())->method('_jsonBackup')->with($this->stringEndsWith('.my_backup.json'), $this->equalTo(array('_OXID_ESHOP_MODULES_CONFIGURATION_' => array('sShopVersion' => '5.1.0', 'sShopEdition' => 'EE', 'sShopId' => 1, 'aModules' => array('mymodule' => array('version' => '1.1.0', 'extend' => array(), 'files' => array('mymoduleitem' => 'my/module/models/mymoduleitem.php')), 'othermodule' => array('version' => '0.1.0', 'extend' => array('basket' => 'other/module/controllers/othermodulebasket', 'oxarticle' => 'other/module/models/othermoduleoxarticle'), 'files' => array()))))))->will($this->returnValue(888)); $this->assertSame(888, $this->SUT->backupToFile(array('modules' => array('mymodule', 'othermodule'), 'settings' => array('version', 'extend', 'files')), 'my_backup')); }