Public Member Functions | |
getConnection ($name) | |
getConnectionTypeInstance ($type) | |
getEntity ($model, $entity) | |
getTableName ($modelEntity) | |
setMappedTableName ($tableName, $mappedName) | |
getMappedTableName ($tableName) | |
cleanDbRow (&$row) | |
createConnection ($name, $type, $config) | |
checkDbConnection () | |
getAutoUpdate () | |
setAutoUpdate ($value) | |
Public Attributes | |
const | AUTO_UPDATE_CACHE_KEY = 'DB_AUTOUPDATE' |
const | AUTO_UPDATE_ONCE = 0 |
const | AUTO_UPDATE_NEVER = -1 |
const | AUTO_UPDATE_ALWAYS = 1 |
Protected Attributes | |
$_connectionTypes = array() | |
$_connections = array() | |
$_entities = array() | |
$_mappedTableNames |
Definition at line 32 of file Resource.php.
checkDbConnection | ( | ) |
Definition at line 198 of file Resource.php.
00199 { 00200 if (!$this->getConnection('core_read')) { 00201 //Mage::app()->getResponse()->setRedirect(Mage::getUrl('install')); 00202 } 00203 }
cleanDbRow | ( | &$ | row | ) |
Definition at line 177 of file Resource.php.
00178 { 00179 if (!empty($row) && is_array($row)) { 00180 foreach ($row as $key=>&$value) { 00181 if (is_string($value) && $value==='0000-00-00 00:00:00') { 00182 $value = ''; 00183 } 00184 } 00185 } 00186 return $this; 00187 }
createConnection | ( | $ | name, | |
$ | type, | |||
$ | config | |||
) |
Definition at line 189 of file Resource.php.
00190 { 00191 if (!isset($this->_connections[$name])) { 00192 $typeObj = $this->getConnectionTypeInstance($type); 00193 $this->_connections[$name] = $typeObj->getConnection($config); 00194 } 00195 return $this->_connections[$name]; 00196 }
getAutoUpdate | ( | ) |
Definition at line 205 of file Resource.php.
00206 { 00207 return self::AUTO_UPDATE_ALWAYS; 00208 #return Mage::app()->loadCache(self::AUTO_UPDATE_CACHE_KEY); 00209 }
getConnection | ( | $ | name | ) |
Creates a connection to resource whenever needed
string | $name |
Definition at line 69 of file Resource.php.
00070 { 00071 if (isset($this->_connections[$name])) { 00072 return $this->_connections[$name]; 00073 } 00074 $connConfig = Mage::getConfig()->getResourceConnectionConfig($name); 00075 00076 if (!$connConfig || !$connConfig->is('active', 1)) { 00077 return false; 00078 } 00079 $origName = $connConfig->getParent()->getName(); 00080 00081 if (isset($this->_connections[$origName])) { 00082 $this->_connections[$name] = $this->_connections[$origName]; 00083 return $this->_connections[$origName]; 00084 } 00085 00086 $typeInstance = $this->getConnectionTypeInstance((string)$connConfig->type); 00087 $conn = $typeInstance->getConnection($connConfig); 00088 00089 $this->_connections[$name] = $conn; 00090 if ($origName!==$name) { 00091 $this->_connections[$origName] = $conn; 00092 } 00093 return $conn; 00094 }
getConnectionTypeInstance | ( | $ | type | ) |
Get connection type instance
Creates new if doesn't exist
string | $type |
Definition at line 104 of file Resource.php.
00105 { 00106 if (!isset($this->_connectionTypes[$type])) { 00107 $config = Mage::getConfig()->getResourceTypeConfig($type); 00108 $typeClass = $config->getClassName(); 00109 $this->_connectionTypes[$type] = new $typeClass(); 00110 } 00111 return $this->_connectionTypes[$type]; 00112 }
getEntity | ( | $ | model, | |
$ | entity | |||
) |
Get resource entity
string | $resource | |
string | $entity |
Definition at line 121 of file Resource.php.
00122 { 00123 //return Mage::getConfig()->getNode("global/models/$model/entities/$entity"); 00124 return Mage::getConfig()->getNode()->global->models->{$model}->entities->{$entity}; 00125 }
getMappedTableName | ( | $ | tableName | ) |
Definition at line 168 of file Resource.php.
00169 { 00170 if (isset($this->_mappedTableNames[$tableName])) { 00171 return $this->_mappedTableNames[$tableName]; 00172 } else { 00173 return false; 00174 } 00175 }
getTableName | ( | $ | modelEntity | ) |
Get resource table name
string | $modelEntity |
Definition at line 133 of file Resource.php.
00134 { 00135 $arr = explode('/', $modelEntity); 00136 if (isset($arr[1])) { 00137 list($model, $entity) = $arr; 00138 //$resourceModel = (string)Mage::getConfig()->getNode('global/models/'.$model.'/resourceModel'); 00139 $resourceModel = (string) Mage::getConfig()->getNode()->global->models->{$model}->resourceModel; 00140 $entityConfig = $this->getEntity($resourceModel, $entity); 00141 if ($entityConfig) { 00142 $tableName = (string)$entityConfig->table; 00143 } else { 00144 Mage::throwException(Mage::helper('core')->__('Can\'t retrieve entity config: %s', $modelEntity)); 00145 } 00146 } else { 00147 $tableName = $modelEntity; 00148 } 00149 00150 Mage::dispatchEvent('resource_get_tablename', array('resource' => $this, 'model_entity' => $modelEntity, 'table_name' => $tableName)); 00151 $mappedTableName = $this->getMappedTableName($tableName); 00152 if ($mappedTableName) { 00153 $tableName = $mappedTableName; 00154 } else { 00155 $tablePrefix = (string)Mage::getConfig()->getTablePrefix(); 00156 $tableName = $tablePrefix . $tableName; 00157 } 00158 00159 return $tableName; 00160 }
setAutoUpdate | ( | $ | value | ) |
Definition at line 211 of file Resource.php.
00212 { 00213 #Mage::app()->saveCache($value, self::AUTO_UPDATE_CACHE_KEY); 00214 return $this; 00215 }
setMappedTableName | ( | $ | tableName, | |
$ | mappedName | |||
) |
Definition at line 162 of file Resource.php.
00163 { 00164 $this->_mappedTableNames[$tableName] = $mappedName; 00165 return $this; 00166 }
$_connections = array() [protected] |
Definition at line 52 of file Resource.php.
$_connectionTypes = array() [protected] |
Definition at line 45 of file Resource.php.
$_entities = array() [protected] |
Definition at line 59 of file Resource.php.
$_mappedTableNames [protected] |
Definition at line 61 of file Resource.php.
const AUTO_UPDATE_ALWAYS = 1 |
Definition at line 38 of file Resource.php.
const AUTO_UPDATE_CACHE_KEY = 'DB_AUTOUPDATE' |
Definition at line 35 of file Resource.php.
const AUTO_UPDATE_NEVER = -1 |
Definition at line 37 of file Resource.php.
const AUTO_UPDATE_ONCE = 0 |
Definition at line 36 of file Resource.php.