Public Member Functions | |
getChecksum ($tables) | |
loadToXml (Mage_Core_Model_Config $xmlConfig, $cond=null) | |
saveConfig ($path, $value, $scope, $scopeId) | |
deleteConfig ($path, $scope, $scopeId) | |
Protected Member Functions | |
_construct () |
Definition at line 28 of file Config.php.
_construct | ( | ) | [protected] |
Resource initialization
Reimplemented from Mage_Core_Model_Resource_Abstract.
Definition at line 30 of file Config.php.
00031 { 00032 $this->_init('core/config_data', 'config_id'); 00033 }
deleteConfig | ( | $ | path, | |
$ | scope, | |||
$ | scopeId | |||
) |
Delete config value
string | $path | |
string | $scope | |
int | $scopeId |
Definition at line 223 of file Config.php.
00224 { 00225 $writeAdapter = $this->_getWriteAdapter(); 00226 $writeAdapter->delete($this->getMainTable(), array( 00227 $writeAdapter->quoteInto('path=?', $path), 00228 $writeAdapter->quoteInto('scope=?', $scope), 00229 $writeAdapter->quoteInto('scope_id=?', $scopeId) 00230 )); 00231 return $this; 00232 }
getChecksum | ( | $ | tables | ) |
Get checksum for one or more tables
string|array | $tables string is separated by comma |
Reimplemented from Mage_Core_Model_Mysql4_Abstract.
Definition at line 41 of file Config.php.
00042 { 00043 if (is_string($tables)) { 00044 $tablesArr = explode(',', $tables); 00045 $tables = array(); 00046 foreach ($tablesArr as $table) { 00047 $table = $this->getTable(trim($table)); 00048 if (!empty($table)) { 00049 $tables[] = $table; 00050 } 00051 } 00052 } 00053 if (empty($tables) || !$this->_getReadAdapter()) { 00054 return false; 00055 } 00056 $checksumArr = $this->_getReadAdapter()->fetchAll('checksum table '.join(',', $tables)); 00057 $checksum = 0; 00058 foreach ($checksumArr as $r) { 00059 $checksum += $r['Checksum']; 00060 } 00061 return $checksum; 00062 }
loadToXml | ( | Mage_Core_Model_Config $ | xmlConfig, | |
$ | cond = null | |||
) |
Load configuration values into xml config object
Mage_Core_Model_Config | $xmlConfig | |
string | $cond |
$extendSource DO NOT need overwrite source
Definition at line 71 of file Config.php.
00072 { 00073 $read = $this->_getReadAdapter(); 00074 if (!$read) { 00075 return $this; 00076 } 00077 00078 $websites = array(); 00079 $rows = $read->fetchAssoc("select website_id, code, name from ".$this->getTable('website')); 00080 foreach ($rows as $w) { 00081 $xmlConfig->setNode('websites/'.$w['code'].'/system/website/id', $w['website_id']); 00082 $xmlConfig->setNode('websites/'.$w['code'].'/system/website/name', $w['name']); 00083 $websites[$w['website_id']] = array('code'=>$w['code']); 00084 } 00085 00086 $stores = array(); 00087 $rows = $read->fetchAssoc("select store_id, code, name, website_id from ".$this->getTable('store')." order by sort_order asc"); 00088 foreach ($rows as $s) { 00089 $xmlConfig->setNode('stores/'.$s['code'].'/system/store/id', $s['store_id']); 00090 $xmlConfig->setNode('stores/'.$s['code'].'/system/store/name', $s['name']); 00091 $xmlConfig->setNode('stores/'.$s['code'].'/system/website/id', $s['website_id']); 00092 $xmlConfig->setNode('websites/'.$websites[$s['website_id']]['code'].'/system/stores/'.$s['code'], $s['store_id']); 00093 $stores[$s['store_id']] = array('code'=>$s['code']); 00094 $websites[$s['website_id']]['stores'][$s['store_id']] = $s['code']; 00095 } 00096 00097 $subst_from = array(); 00098 $subst_to = array(); 00099 00100 // load all configuration records from database, which are not inherited 00101 $rows = $read->fetchAll("select scope, scope_id, path, value from ".$this->getMainTable().($cond ? ' where '.$cond : '')); 00102 00103 // set default config values from database 00104 foreach ($rows as $r) { 00105 if ($r['scope']!=='default') { 00106 continue; 00107 } 00108 $value = str_replace($subst_from, $subst_to, $r['value']); 00109 $xmlConfig->setNode('default/'.$r['path'], $value); 00110 } 00111 // inherit default config values to all websites 00112 $extendSource = $xmlConfig->getNode('default'); 00113 foreach ($websites as $id=>$w) { 00114 $websiteNode = $xmlConfig->getNode('websites/'.$w['code']); 00115 $websiteNode->extend($extendSource); 00116 } 00117 00118 $deleteWebsites = array(); 00119 // set websites config values from database 00120 foreach ($rows as $r) { 00121 if ($r['scope']!=='websites') { 00122 continue; 00123 } 00124 $value = str_replace($subst_from, $subst_to, $r['value']); 00125 if (isset($websites[$r['scope_id']])) { 00126 $xmlConfig->setNode('websites/'.$websites[$r['scope_id']]['code'].'/'.$r['path'], $value); 00127 } 00128 else { 00129 $deleteWebsites[$r['scope_id']] = $r['scope_id']; 00130 } 00131 } 00132 00133 // extend website config values to all associated stores 00134 foreach ($websites as $website) { 00135 $extendSource = $xmlConfig->getNode('websites/'.$website['code']); 00136 if (isset($website['stores'])) { 00137 foreach ($website['stores'] as $sCode) { 00138 $storeNode = $xmlConfig->getNode('stores/'.$sCode); 00139 /** 00140 * $extendSource DO NOT need overwrite source 00141 */ 00142 $storeNode->extend($extendSource, false); 00143 } 00144 } 00145 } 00146 00147 $deleteStores = array(); 00148 // set stores config values from database 00149 foreach ($rows as $r) { 00150 if ($r['scope']!=='stores') { 00151 continue; 00152 } 00153 $value = str_replace($subst_from, $subst_to, $r['value']); 00154 if (isset($stores[$r['scope_id']])) { 00155 $xmlConfig->setNode('stores/'.$stores[$r['scope_id']]['code'].'/'.$r['path'], $value); 00156 } 00157 else { 00158 $deleteStores[$r['scope_id']] = $r['scope_id']; 00159 } 00160 } 00161 00162 if ($deleteWebsites) { 00163 $this->_getWriteAdapter()->delete($this->getMainTable(), array( 00164 $this->_getWriteAdapter()->quoteInto('scope=?', 'websites'), 00165 $this->_getWriteAdapter()->quoteInto('scope_id IN(?)', $deleteWebsites), 00166 )); 00167 } 00168 00169 if ($deleteStores) { 00170 $this->_getWriteAdapter()->delete($this->getMainTable(), array( 00171 $this->_getWriteAdapter()->quoteInto('scope=?', 'stores'), 00172 $this->_getWriteAdapter()->quoteInto('scope_id IN(?)', $deleteStores), 00173 )); 00174 } 00175 00176 return $this; 00177 }
saveConfig | ( | $ | path, | |
$ | value, | |||
$ | scope, | |||
$ | scopeId | |||
) |
Save config value
string | $path | |
string | $value | |
string | $scope | |
int | $scopeId |
Definition at line 188 of file Config.php.
00189 { 00190 $writeAdapter = $this->_getWriteAdapter(); 00191 $select = $writeAdapter->select() 00192 ->from($this->getMainTable()) 00193 ->where('path=?', $path) 00194 ->where('scope=?', $scope) 00195 ->where('scope_id=?', $scopeId); 00196 $row = $writeAdapter->fetchRow($select); 00197 00198 $newData = array( 00199 'scope' => $scope, 00200 'scope_id' => $scopeId, 00201 'path' => $path, 00202 'value' => $value 00203 ); 00204 00205 if ($row) { 00206 $whereCondition = $writeAdapter->quoteInto($this->getIdFieldName() . '=?', $row[$this->getIdFieldName()]); 00207 $writeAdapter->update($this->getMainTable(), $newData, $whereCondition); 00208 } 00209 else { 00210 $writeAdapter->insert($this->getMainTable(), $newData); 00211 } 00212 return $this; 00213 }