本文整理汇总了PHP中Mage_Core_Model_Resource_Setup::_hadUpdates方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Core_Model_Resource_Setup::_hadUpdates方法的具体用法?PHP Mage_Core_Model_Resource_Setup::_hadUpdates怎么用?PHP Mage_Core_Model_Resource_Setup::_hadUpdates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Core_Model_Resource_Setup
的用法示例。
在下文中一共展示了Mage_Core_Model_Resource_Setup::_hadUpdates方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _modifyResourceDb
/**
* Run module modification files. Return version of last applied upgrade (false if no upgrades applied)
*
* @param string $actionType install|upgrade|uninstall
* @param string $fromVersion
* @param string $toVersion
* @return string | false
*/
protected function _modifyResourceDb($actionType, $fromVersion, $toVersion)
{
$resModel = (string) $this->_connectionConfig->model;
$modName = (string) $this->_moduleConfig[0]->getName();
$sqlFilesDir = Mage::getModuleDir('sql', $modName) . DS . $this->_resourceName;
if (!is_dir($sqlFilesDir) || !is_readable($sqlFilesDir)) {
return false;
}
// Read resource files
$arrAvailableFiles = array();
$sqlDir = dir($sqlFilesDir);
while (false !== ($sqlFile = $sqlDir->read())) {
$matches = array();
if (preg_match('#^' . $resModel . '-' . $actionType . '-(.*)\\.(sql|php)$#i', $sqlFile, $matches)) {
$arrAvailableFiles[$matches[1]] = $sqlFile;
}
}
$sqlDir->close();
if (empty($arrAvailableFiles)) {
return false;
}
// Get SQL files name
$arrModifyFiles = $this->_getModifySqlFiles($actionType, $fromVersion, $toVersion, $arrAvailableFiles);
if (empty($arrModifyFiles)) {
return false;
}
$modifyVersion = false;
foreach ($arrModifyFiles as $resourceFile) {
$sqlFile = $sqlFilesDir . DS . $resourceFile['fileName'];
$fileType = pathinfo($resourceFile['fileName'], PATHINFO_EXTENSION);
// Execute SQL
if ($this->_conn) {
$this->_conn->disallowDdlCache();
try {
switch ($fileType) {
case 'sql':
$sql = file_get_contents($sqlFile);
if ($sql != '') {
$result = $this->run($sql);
} else {
$result = true;
}
break;
case 'php':
$conn = $this->_conn;
$result = (include $sqlFile);
break;
default:
$result = false;
}
if ($result) {
if (strpos($actionType, 'data-') !== false) {
$this->_getResource()->setDataVersion($this->_resourceName, $resourceFile['toVersion']);
} else {
$this->_getResource()->setDbVersion($this->_resourceName, $resourceFile['toVersion']);
}
}
} catch (Exception $e) {
echo "<pre>" . print_r($e, 1) . "</pre>";
throw Mage::exception('Mage_Core', Mage::helper('core')->__('Error in file: "%s" - %s', $sqlFile, $e->getMessage()));
}
$this->_conn->allowDdlCache();
}
$modifyVersion = $resourceFile['toVersion'];
}
self::$_hadUpdates = true;
return $modifyVersion;
}
示例2: _modifyResourceDb
/**
* Run module modification files. Return version of last applied upgrade (false if no upgrades applied)
*
* @param string $actionType self::TYPE_*
* @param string $fromVersion
* @param string $toVersion
* @return string|false
* @throws Mage_Core_Exception
*/
protected function _modifyResourceDb($actionType, $fromVersion, $toVersion)
{
switch ($actionType) {
case self::TYPE_DB_INSTALL:
case self::TYPE_DB_UPGRADE:
$files = $this->_getAvailableDbFiles($actionType, $fromVersion, $toVersion);
break;
case self::TYPE_DATA_INSTALL:
case self::TYPE_DATA_UPGRADE:
$files = $this->_getAvailableDataFiles($actionType, $fromVersion, $toVersion);
break;
default:
$files = array();
break;
}
if (empty($files) || !$this->getConnection()) {
return false;
}
$version = false;
foreach ($files as $file) {
$fileName = $file['fileName'];
$fileType = pathinfo($fileName, PATHINFO_EXTENSION);
$this->getConnection()->disallowDdlCache();
try {
switch ($fileType) {
case 'php':
$conn = $this->getConnection();
$result = (include $fileName);
break;
case 'sql':
$sql = file_get_contents($fileName);
if (!empty($sql)) {
$result = $this->run($sql);
} else {
$result = true;
}
break;
default:
$result = false;
break;
}
if ($result) {
$this->_setResourceVersion($actionType, $file['toVersion']);
}
} catch (Exception $e) {
throw Mage::exception('Mage_Core', Mage::helper('core')->__('Error in file: "%s" - %s', $fileName, $e->getMessage()));
}
$version = $file['toVersion'];
$this->getConnection()->allowDdlCache();
}
self::$_hadUpdates = true;
return $version;
}
示例3: _modifyResourceDb
/**
* Run module modification sql
*
* @param string $actionType install|upgrade|uninstall
* @param string $fromVersion
* @param string $toVersion
* @return bool
*/
protected function _modifyResourceDb($actionType, $fromVersion, $toVersion)
{
$resModel = (string) $this->_connectionConfig->model;
$modName = (string) $this->_moduleConfig[0]->getName();
$sqlFilesDir = Mage::getModuleDir('sql', $modName) . DS . $this->_resourceName;
if (!is_dir($sqlFilesDir) || !is_readable($sqlFilesDir)) {
return false;
}
// Read resource files
$arrAvailableFiles = array();
$sqlDir = dir($sqlFilesDir);
while (false !== ($sqlFile = $sqlDir->read())) {
if (preg_match('#^' . $resModel . '-' . $actionType . '-(.*)\\.(sql|php)$#i', $sqlFile, $matches)) {
$arrAvailableFiles[$matches[1]] = $sqlFile;
}
}
$sqlDir->close();
if (empty($arrAvailableFiles)) {
return false;
}
// Get SQL files name
$arrModifyFiles = $this->_getModifySqlFiles($actionType, $fromVersion, $toVersion, $arrAvailableFiles);
if (empty($arrModifyFiles)) {
return false;
}
foreach ($arrModifyFiles as $resourceFile) {
$sqlFile = $sqlFilesDir . DS . $resourceFile['fileName'];
$fileType = pathinfo($resourceFile['fileName'], PATHINFO_EXTENSION);
// Execute SQL
if ($this->_conn) {
try {
switch ($fileType) {
case 'sql':
$sql = file_get_contents($sqlFile);
if ($sql != '') {
$result = $this->run($sql);
} else {
$result = true;
}
break;
case 'php':
$conn = $this->_conn;
/**
* useful variables:
* - $conn: setup db connection
* - $sqlFilesDir: root dir for sql update files
*/
try {
#$conn->beginTransaction();
$result = (include $sqlFile);
#$conn->commit();
} catch (Exception $e) {
#$conn->rollback();
throw $e;
}
break;
default:
$result = false;
}
if ($result) {
$this->run("replace into " . $this->getTable('core/resource') . " (code, version) values ('" . $this->_resourceName . "', '" . $resourceFile['toVersion'] . "')");
#Mage::getResourceModel('core/resource')->setDbVersion(
# $this->_resourceName, $resourceFile['toVersion']);
}
} catch (Exception $e) {
echo "<pre>" . print_r($e, 1) . "</pre>";
throw Mage::exception('Mage_Core', Mage::helper('core')->__('Error in file: "%s" - %s', $sqlFile, $e->getMessage()));
}
}
$toVersion = $resourceFile['toVersion'];
}
self::$_hadUpdates = true;
return $toVersion;
}