00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #require_once 'Mage/Core/Model/Mysql4.php';
00028
00029
00030
00031
00032 class Mage_Core_Model_Mysql4_Resource
00033 {
00034 protected $_read = null;
00035 protected $_write = null;
00036 protected $_resTable = null;
00037 protected static $_versions = null;
00038
00039 public function __construct()
00040 {
00041 $this->_resTable = Mage::getSingleton('core/resource')->getTableName('core/resource');
00042 $this->_read = Mage::getSingleton('core/resource')->getConnection('core_read');
00043 $this->_write = Mage::getSingleton('core/resource')->getConnection('core_write');
00044 }
00045
00046
00047
00048
00049
00050
00051
00052 function getDbVersion($resName)
00053 {
00054 if (!$this->_read) {
00055 return false;
00056 }
00057
00058 if (is_null(self::$_versions)) {
00059
00060 try {
00061 $select = $this->_read->select()->from($this->_resTable, array('code', 'version'));
00062 self::$_versions = $this->_read->fetchPairs($select);
00063 }
00064 catch (Exception $e){
00065 self::$_versions = array();
00066 }
00067 }
00068 return isset(self::$_versions[$resName]) ? self::$_versions[$resName] : false;
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078 function setDbVersion($resName, $version)
00079 {
00080 $dbModuleInfo = array(
00081 'code' => $resName,
00082 'version' => $version,
00083 );
00084
00085 if ($this -> getDbVersion($resName)) {
00086 self::$_versions[$resName] = $version;
00087 $condition = $this->_write->quoteInto('code=?', $resName);
00088 return $this->_write->update($this->_resTable, $dbModuleInfo, $condition);
00089 }
00090 else {
00091 self::$_versions[$resName] = $version;
00092 return $this->_write->insert($this->_resTable, $dbModuleInfo);
00093 }
00094 }
00095 }