|
|
@@ -16,12 +16,32 @@ define('BX_DOL_STUDIO_IU_RC_SUCCESS', 0);
|
|
|
define('BX_DOL_STUDIO_IU_RC_FAILED', 1);
|
|
|
define('BX_DOL_STUDIO_IU_RC_SCHEDULED', 2);
|
|
|
|
|
|
+/*
|
|
|
+ * Errors list.
|
|
|
+ * It can be broaden later.
|
|
|
+ */
|
|
|
+define('BX_DOL_STUDIO_IU_RCE_NOT_FOUND', 100);
|
|
|
+define('BX_DOL_STUDIO_IU_RCE_NOT_AVAILABLE', 101);
|
|
|
+define('BX_DOL_STUDIO_IU_RCE_NOT_AUTHORIZED', 102);
|
|
|
+define('BX_DOL_STUDIO_IU_RCE_ALREADY_PERFORMED', 103);
|
|
|
+define('BX_DOL_STUDIO_IU_RCE_UNIQUE_PARAMS_USED', 104);
|
|
|
+define('BX_DOL_STUDIO_IU_RCE_WSV_MI', 105); //--- Wrong script version during module install
|
|
|
+define('BX_DOL_STUDIO_IU_RCE_WSV_MU', 106); //--- Wrong script version during module update
|
|
|
+define('BX_DOL_STUDIO_IU_RCE_WMV', 107); //--- Wrong module version during module update
|
|
|
+define('BX_DOL_STUDIO_IU_RCE_MODIFIED', 108);
|
|
|
+define('BX_DOL_STUDIO_IU_RCE_CHECKSUM_FAILED', 109);
|
|
|
+
|
|
|
+define('BX_DOL_STUDIO_IU_RCE_SUBACTION_FAILED', 200); //--- Error appeared in some subaction
|
|
|
+
|
|
|
+
|
|
|
class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSingleton
|
|
|
{
|
|
|
- protected $bUseFtp;
|
|
|
+ protected $bUseFtp;
|
|
|
+
|
|
|
+ protected $sAuthorizedAccessClass;
|
|
|
+ protected $sStoreDataUrlPublic;
|
|
|
|
|
|
- protected $sAuthorizedAccessClass;
|
|
|
- protected $sStoreDataUrlPublic;
|
|
|
+ protected $_oLog;
|
|
|
|
|
|
public function __construct()
|
|
|
{
|
|
|
@@ -32,8 +52,11 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
|
|
|
|
|
|
$this->bUseFtp = BX_FORCE_USE_FTP_FILE_TRANSFER;
|
|
|
|
|
|
- $this->sAuthorizedAccessClass = 'BxDolStudioOAuthOAuth2';
|
|
|
- $this->sStoreDataUrlPublic = BX_DOL_MARKET_URL_INTEGRATION;
|
|
|
+ $this->sAuthorizedAccessClass = 'BxDolStudioOAuthOAuth2';
|
|
|
+ $this->sStoreDataUrlPublic = BX_DOL_MARKET_URL_INTEGRATION;
|
|
|
+
|
|
|
+ $this->_oLog = BxDolLog::getInstance();
|
|
|
+ $this->_oLog->setName('upgrade_modules');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -66,7 +89,7 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
|
|
|
return 'sys_download_file_complete_' . $sParam;
|
|
|
}
|
|
|
|
|
|
- public static function getNamePerformModulesUpgrade()
|
|
|
+ public static function getNamePerformModulesUpgrade()
|
|
|
{
|
|
|
return 'sys_upgrade_modules_transient';
|
|
|
}
|
|
|
@@ -82,17 +105,17 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
|
|
|
/*
|
|
|
* Is used to perform action inside Transient Cron Job.
|
|
|
*/
|
|
|
- public function servicePerformAction($sDirectory, $sOperation, $aParams)
|
|
|
+ public function servicePerformAction($sDirectory, $sOperation, $aParams)
|
|
|
{
|
|
|
return $this->perform($sDirectory, $sOperation, array_merge($aParams, array('transient' => true)));
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
+ /*
|
|
|
* Is used to perform modules upgrade inside Transient Cron Job.
|
|
|
*/
|
|
|
- public function servicePerformModulesUpgrade($bEmailNotify)
|
|
|
+ public function servicePerformModulesUpgrade($aParams = array())
|
|
|
{
|
|
|
- return $this->performModulesUpgrade(true, $bEmailNotify);
|
|
|
+ return $this->performModulesUpgrade(array_merge($aParams, array('directly' => true, 'transient' => true)));
|
|
|
}
|
|
|
|
|
|
public function getStoreDataUrl($sType = 'public')
|
|
|
@@ -102,10 +125,10 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
|
|
|
|
|
|
public function getAccessObject($bAuthorizedAccess)
|
|
|
{
|
|
|
- $sClass = $bAuthorizedAccess ? $this->sAuthorizedAccessClass : 'BxDolStudioJson';
|
|
|
+ $sClass = $bAuthorizedAccess ? $this->sAuthorizedAccessClass : 'BxDolStudioJson';
|
|
|
|
|
|
- bx_import($sClass);
|
|
|
- return $sClass::getInstance();
|
|
|
+ bx_import($sClass);
|
|
|
+ return $sClass::getInstance();
|
|
|
}
|
|
|
|
|
|
public function getModules($bTitleAsKey = true)
|
|
|
@@ -126,7 +149,7 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
|
|
|
if(!is_dir($sPath . $sVendor . '/' . $sModule) || substr($sModule, 0, 1) == '.')
|
|
|
continue;
|
|
|
|
|
|
- $sModulePath = $sVendor . '/' . $sModule . '/';
|
|
|
+ $sModulePath = $sVendor . '/' . $sModule . '/';
|
|
|
$aModule = $this->getConfigModule($sPath . $sModulePath . 'install/config.php', !empty($aInstalledInfo[$sModulePath]) ? $aInstalledInfo[$sModulePath] : array());
|
|
|
if(empty($aModule))
|
|
|
continue;
|
|
|
@@ -162,13 +185,13 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
|
|
|
if(!is_dir($sPath . $sVendor . '/' . $sModule) || substr($sModule, 0, 1) == '.')
|
|
|
continue;
|
|
|
|
|
|
- $sModulePath = $sVendor . '/' . $sModule . '/';
|
|
|
- if(empty($aInstalledInfo[$sModulePath]))
|
|
|
- continue;
|
|
|
+ $sModulePath = $sVendor . '/' . $sModule . '/';
|
|
|
+ if(empty($aInstalledInfo[$sModulePath]))
|
|
|
+ continue;
|
|
|
|
|
|
- $aUpdate = $this->getUpdate($aInstalledInfo[$sModulePath]);
|
|
|
- if(!empty($aUpdate))
|
|
|
- $aUpdates[$aUpdate['title']] = $aUpdate;
|
|
|
+ $aUpdate = $this->getUpdate($aInstalledInfo[$sModulePath]);
|
|
|
+ if(!empty($aUpdate))
|
|
|
+ $aUpdates[$aUpdate['title']] = $aUpdate;
|
|
|
}
|
|
|
closedir($rHandleModule);
|
|
|
}
|
|
|
@@ -182,55 +205,55 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
|
|
|
|
|
|
public function getUpdate($mixedModule)
|
|
|
{
|
|
|
- $aResult = array();
|
|
|
+ $aResult = array();
|
|
|
|
|
|
- if(!is_array($mixedModule))
|
|
|
- $mixedModule = BxDolModuleQuery::getInstance()->{is_numeric($mixedModule) ? 'getModuleById' : 'getModuleByName'}($mixedModule);
|
|
|
+ if(!is_array($mixedModule))
|
|
|
+ $mixedModule = BxDolModuleQuery::getInstance()->{is_numeric($mixedModule) ? 'getModuleById' : 'getModuleByName'}($mixedModule);
|
|
|
|
|
|
- if(empty($mixedModule) || !is_array($mixedModule))
|
|
|
- return $aResult;
|
|
|
+ if(empty($mixedModule) || !is_array($mixedModule))
|
|
|
+ return $aResult;
|
|
|
|
|
|
- $sPathModule = BX_DIRECTORY_PATH_MODULES . $mixedModule['path'];
|
|
|
- $sPathUpdates = $sPathModule . 'updates/';
|
|
|
+ $sPathModule = BX_DIRECTORY_PATH_MODULES . $mixedModule['path'];
|
|
|
+ $sPathUpdates = $sPathModule . 'updates/';
|
|
|
|
|
|
- $rHandleUpdate = @opendir($sPathUpdates);
|
|
|
- if($rHandleUpdate === false)
|
|
|
- return $aResult;
|
|
|
+ $rHandleUpdate = @opendir($sPathUpdates);
|
|
|
+ if($rHandleUpdate === false)
|
|
|
+ return $aResult;
|
|
|
|
|
|
- while(($sUpdate = readdir($rHandleUpdate)) !== false) {
|
|
|
- $sPathUpdate = $sPathUpdates . $sUpdate . '/';
|
|
|
- if(substr($sUpdate, 0, 1) == '.' || !is_dir($sPathUpdate))
|
|
|
- continue;
|
|
|
+ while(($sUpdate = readdir($rHandleUpdate)) !== false) {
|
|
|
+ $sPathUpdate = $sPathUpdates . $sUpdate . '/';
|
|
|
+ if(substr($sUpdate, 0, 1) == '.' || !is_dir($sPathUpdate))
|
|
|
+ continue;
|
|
|
|
|
|
- $aUpdate = $this->getConfigUpdate($sPathModule . 'install/config.php', $sPathUpdate . 'install/config.php', $mixedModule);
|
|
|
- if(empty($aUpdate) || !is_array($aUpdate) || version_compare($aUpdate['module_version'], $aUpdate['version_from']) != 0)
|
|
|
- continue;
|
|
|
+ $aUpdate = $this->getConfigUpdate($sPathModule . 'install/config.php', $sPathUpdate . 'install/config.php', $mixedModule);
|
|
|
+ if(empty($aUpdate) || !is_array($aUpdate) || version_compare($aUpdate['module_version'], $aUpdate['version_from']) != 0)
|
|
|
+ continue;
|
|
|
|
|
|
- $aResult = $aUpdate;
|
|
|
- break;
|
|
|
- }
|
|
|
+ $aResult = $aUpdate;
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- closedir($rHandleUpdate);
|
|
|
+ closedir($rHandleUpdate);
|
|
|
|
|
|
return $aResult;
|
|
|
}
|
|
|
|
|
|
public function perform($sDirectory, $sOperation, $aParams = array())
|
|
|
{
|
|
|
- $bTransient = false;
|
|
|
- if(isset($aParams['transient']) && $aParams['transient'] === true) {
|
|
|
- $bTransient = true;
|
|
|
- unset($aParams['transient']);
|
|
|
- }
|
|
|
+ $bTransient = false;
|
|
|
+ if(isset($aParams['transient'])) {
|
|
|
+ $bTransient = (bool)$aParams['transient'];
|
|
|
+ unset($aParams['transient']);
|
|
|
+ }
|
|
|
|
|
|
- if(!defined('BX_DOL_CRON_EXECUTE') && !self::isRealOwner() && !in_array($sOperation, array('install', 'uninstall', 'enable', 'disable'))) {
|
|
|
- if($this->addTransientJob(self::getNamePerformAction($sDirectory), 'perform_action', array($sDirectory, $sOperation, $aParams)))
|
|
|
- return array('code' => BX_DOL_STUDIO_IU_RC_SCHEDULED, 'message' => _t('_adm_mod_msg_process_operation_scheduled'));
|
|
|
- else
|
|
|
- return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_mod_err_process_operation_failed', $sOperation, $sDirectory));
|
|
|
- }
|
|
|
+ if(!defined('BX_DOL_CRON_EXECUTE') && !self::isRealOwner() && !in_array($sOperation, array('install', 'uninstall', 'enable', 'disable'))) {
|
|
|
+ if($this->addTransientJob(self::getNamePerformAction($sDirectory), 'perform_action', array($sDirectory, $sOperation, $aParams)))
|
|
|
+ return array('code' => BX_DOL_STUDIO_IU_RC_SCHEDULED, 'message' => _t('_adm_mod_msg_process_operation_scheduled'));
|
|
|
+ else
|
|
|
+ return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_mod_err_process_operation_failed', $sOperation, $sDirectory));
|
|
|
+ }
|
|
|
|
|
|
- $sConfigFile = 'install/config.php';
|
|
|
+ $sConfigFile = 'install/config.php';
|
|
|
$sInstallerFile = 'install/installer.php';
|
|
|
$sInstallerClass = $sOperation == 'update' ? 'Updater' : 'Installer';
|
|
|
|
|
|
@@ -238,37 +261,59 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
|
|
|
|
|
|
$sPathInstaller = BX_DIRECTORY_PATH_MODULES . $sDirectory . $sInstallerFile;
|
|
|
if(empty($aConfig) || !file_exists($sPathInstaller)) {
|
|
|
- $sMessage = _t('_adm_mod_err_process_operation_failed', $sOperation, $sDirectory);
|
|
|
- if($bTransient)
|
|
|
- $this->emailNotify($sMessage);
|
|
|
+ $sMessage = _t('_adm_mod_err_process_operation_failed', $sOperation, $sDirectory);
|
|
|
|
|
|
- return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => $sMessage);
|
|
|
+ $this->_oLog->write('Operation failed:', $sMessage);
|
|
|
+ if($bTransient)
|
|
|
+ $this->emailNotify($sMessage);
|
|
|
+
|
|
|
+ return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => $sMessage);
|
|
|
}
|
|
|
|
|
|
- require_once($sPathInstaller);
|
|
|
+ require_once($sPathInstaller);
|
|
|
+
|
|
|
+ $sClassName = $aConfig['class_prefix'] . $sInstallerClass;
|
|
|
+ $oInstaller = new $sClassName($aConfig);
|
|
|
+ $aResult = $oInstaller->$sOperation($aParams);
|
|
|
|
|
|
- $sClassName = $aConfig['class_prefix'] . $sInstallerClass;
|
|
|
- $oInstaller = new $sClassName($aConfig);
|
|
|
- $aResult = $oInstaller->$sOperation($aParams);
|
|
|
+ if(!$aResult['result']) {
|
|
|
+ $this->_oLog->write('Operation failed:', $aResult['message']);
|
|
|
|
|
|
- if(!$aResult['result'] && $bTransient)
|
|
|
- $this->emailNotify($aResult['message']);
|
|
|
+ if($bTransient)
|
|
|
+ $this->emailNotify($aResult['message']);
|
|
|
+ }
|
|
|
|
|
|
- return array('code' => $aResult['result'] ? BX_DOL_STUDIO_IU_RC_SUCCESS : BX_DOL_STUDIO_IU_RC_FAILED, 'message' => $aResult['message']);
|
|
|
+ return array(
|
|
|
+ 'code' => isset($aResult['code']) ? $aResult['code'] : ($aResult['result'] ? BX_DOL_STUDIO_IU_RC_SUCCESS : BX_DOL_STUDIO_IU_RC_FAILED),
|
|
|
+ 'message' => $aResult['message']
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
- public function performModulesUpgrade($bDirectly = true, $bEmailNotify = true)
|
|
|
+ /**
|
|
|
+ * Update modules using cron based auto updates.
|
|
|
+ * @see BxDolCronUpgradeModulesCheck
|
|
|
+ */
|
|
|
+ public function performModulesUpgrade($aParams = array())
|
|
|
{
|
|
|
- if(!defined('BX_DOL_CRON_EXECUTE') && !$bDirectly)
|
|
|
- return $this->addTransientJob(self::getNamePerformModulesUpgrade(), 'perform_modules_upgrade', array($bEmailNotify));
|
|
|
+ $bDirectly = true;
|
|
|
+ if(isset($aParams['directly'])) {
|
|
|
+ $bDirectly = (bool)$aParams['directly'];
|
|
|
+ unset($aParams['directly']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $bTransient = true;
|
|
|
+ if(isset($aParams['transient'])) {
|
|
|
+ $bTransient = (bool)$aParams['transient'];
|
|
|
+ unset($aParams['transient']);
|
|
|
+ }
|
|
|
|
|
|
- $oLog = BxDolLog::getInstance();
|
|
|
- $oLog->setName('upgrade_modules');
|
|
|
+ if(!defined('BX_DOL_CRON_EXECUTE') && !$bDirectly)
|
|
|
+ return $this->addTransientJob(self::getNamePerformModulesUpgrade(), 'perform_modules_upgrade', array($aParams));
|
|
|
|
|
|
$aFailed = array();
|
|
|
$aUpdates = $this->checkUpdates();
|
|
|
if(empty($aUpdates) || !is_array($aUpdates)) {
|
|
|
- $oLog->write('Cannot get a list of modules which require to be updated.');
|
|
|
+ $this->_oLog->write('Cannot get a list of modules which require to be updated.');
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -283,31 +328,37 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
|
|
|
$aSuccess = array();
|
|
|
$aUpdates = $this->getUpdates();
|
|
|
if(empty($aUpdates) || !is_array($aUpdates)) {
|
|
|
- $oLog->write('Cannot find update scripts for modules. They are damaged or were not downloaded.');
|
|
|
+ $this->_oLog->write('Cannot find update scripts for modules. They are damaged or were not downloaded.');
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
foreach($aUpdates as $aUpdate) {
|
|
|
- $aResult = $this->perform($aUpdate['dir'], 'update');
|
|
|
- if((int)$aResult['code'] != 0) {
|
|
|
- $aFailed[$aUpdate['module_name']] = $aResult['message'];
|
|
|
- continue;
|
|
|
+ $aResult = $this->perform($aUpdate['dir'], 'update', $aParams);
|
|
|
+ switch((int)$aResult['code']) {
|
|
|
+ case BX_DOL_STUDIO_IU_RC_SUCCESS:
|
|
|
+ $aSuccess[$aUpdate['module_name']] = $aUpdate['version_to'];
|
|
|
+ break;
|
|
|
+
|
|
|
+ case BX_DOL_STUDIO_IU_RCE_WSV_MU:
|
|
|
+ if(isset($aParams['autoupdate']) && (bool)$aParams['autoupdate'] === true)
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ $aFailed[$aUpdate['module_name']] = $aResult['message'];
|
|
|
}
|
|
|
-
|
|
|
- $aSuccess[$aUpdate['module_name']] = $aUpdate['version_to'];
|
|
|
}
|
|
|
|
|
|
if(!empty($aFailed)) {
|
|
|
- $oLog->write('Failed to update modules:', $aFailed);
|
|
|
+ $this->_oLog->write('Failed to update modules:', $aFailed);
|
|
|
|
|
|
- if($bEmailNotify)
|
|
|
+ if($bTransient)
|
|
|
$this->emailNotifyModulesUpgrade('failed', $aFailed);
|
|
|
}
|
|
|
|
|
|
if(!empty($aSuccess)) {
|
|
|
- $oLog->write('Successfully updated modules:', $aSuccess);
|
|
|
+ $this->_oLog->write('Successfully updated modules:', $aSuccess);
|
|
|
|
|
|
- if($bEmailNotify)
|
|
|
+ if($bTransient)
|
|
|
$this->emailNotifyModulesUpgrade('success', $aSuccess);
|
|
|
}
|
|
|
|
|
|
@@ -318,28 +369,28 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
|
|
|
{
|
|
|
$iPerPage = 9999; //--- Note. It's essential to load all purchased products at the same time.
|
|
|
|
|
|
- if($bAuthorizedAccess)
|
|
|
- $aProducts = $this->getAccessObject(true)->loadItems(array(
|
|
|
- 'method' => 'browse_purchased',
|
|
|
- 'domain' => BX_DOL_URL_ROOT,
|
|
|
- 'products' => $this->getInstalledInfoShort(),
|
|
|
- 'per_page' => $iPerPage
|
|
|
- ));
|
|
|
- else
|
|
|
- $aProducts = $this->getAccessObject(false)->load($this->sStoreDataUrlPublic . 'json_browse_purchased', array('key' => getParam('sys_oauth_key'), 'per_page' => $iPerPage));
|
|
|
+ if($bAuthorizedAccess)
|
|
|
+ $aProducts = $this->getAccessObject(true)->loadItems(array(
|
|
|
+ 'method' => 'browse_purchased',
|
|
|
+ 'domain' => BX_DOL_URL_ROOT,
|
|
|
+ 'products' => $this->getInstalledInfoShort(),
|
|
|
+ 'per_page' => $iPerPage
|
|
|
+ ));
|
|
|
+ else
|
|
|
+ $aProducts = $this->getAccessObject(false)->load($this->sStoreDataUrlPublic . 'json_browse_purchased', array('key' => getParam('sys_oauth_key'), 'per_page' => $iPerPage));
|
|
|
|
|
|
- if(empty($aProducts) || !is_array($aProducts))
|
|
|
- return $aProducts;
|
|
|
+ if(empty($aProducts) || !is_array($aProducts))
|
|
|
+ return $aProducts;
|
|
|
|
|
|
- $oModuleDb = BxDolModuleQuery::getInstance();
|
|
|
+ $oModuleDb = BxDolModuleQuery::getInstance();
|
|
|
|
|
|
- $oModuleDb->updateModule(array('hash' => ''));
|
|
|
+ $oModuleDb->updateModule(array('hash' => ''));
|
|
|
if(!empty($aProducts) && is_array($aProducts))
|
|
|
- foreach ($aProducts as $aProduct)
|
|
|
- if(!empty($aProduct['hash']))
|
|
|
- $oModuleDb->updateModule(array('hash' => $aProduct['hash']), array('name' => $aProduct['name']));
|
|
|
+ foreach ($aProducts as $aProduct)
|
|
|
+ if(!empty($aProduct['hash']))
|
|
|
+ $oModuleDb->updateModule(array('hash' => $aProduct['hash']), array('name' => $aProduct['name']));
|
|
|
|
|
|
- return $aProducts;
|
|
|
+ return $aProducts;
|
|
|
}
|
|
|
|
|
|
public function checkUpdates($bAuthorizedAccess = false)
|
|
|
@@ -347,77 +398,82 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
|
|
|
$sProducts = $this->getInstalledInfoShort();
|
|
|
|
|
|
if($bAuthorizedAccess)
|
|
|
- return $this->getAccessObject(true)->loadItems(array(
|
|
|
- 'method' => 'browse_updates',
|
|
|
- 'products' => $sProducts
|
|
|
- ));
|
|
|
+ return $this->getAccessObject(true)->loadItems(array(
|
|
|
+ 'method' => 'browse_updates',
|
|
|
+ 'products' => $sProducts
|
|
|
+ ));
|
|
|
|
|
|
- return $this->getAccessObject(false)->load($this->sStoreDataUrlPublic . 'json_browse_updates', array(
|
|
|
- 'key' => getParam('sys_oauth_key'),
|
|
|
- 'products' => $sProducts
|
|
|
- ));
|
|
|
+ return $this->getAccessObject(false)->load($this->sStoreDataUrlPublic . 'json_browse_updates', array(
|
|
|
+ 'key' => getParam('sys_oauth_key'),
|
|
|
+ 'products' => $sProducts
|
|
|
+ ));
|
|
|
}
|
|
|
|
|
|
public function downloadFileAuthorized($iFileId)
|
|
|
{
|
|
|
- $aItem = $this->getAccessObject(true)->loadItems(array(
|
|
|
- 'method' => 'download_file',
|
|
|
- 'file_id' => $iFileId
|
|
|
- ));
|
|
|
+ $aItem = $this->getAccessObject(true)->loadItems(array(
|
|
|
+ 'method' => 'download_file',
|
|
|
+ 'file_id' => $iFileId
|
|
|
+ ));
|
|
|
|
|
|
- if(empty($aItem) || !is_array($aItem))
|
|
|
- return $aItem;
|
|
|
+ if(empty($aItem) || !is_array($aItem))
|
|
|
+ return $aItem;
|
|
|
|
|
|
- return $this->downloadFileInit($aItem, array('module_name' => $aItem['module_name']));
|
|
|
+ return $this->downloadFileInit($aItem, array('module_name' => $aItem['module_name']));
|
|
|
}
|
|
|
|
|
|
- public function downloadUpdatePublic($sModuleName, $bAutoUpdate = false)
|
|
|
+ public function downloadUpdatePublic($sModuleName, $bApplyUpdate = false)
|
|
|
{
|
|
|
- $aModule = BxDolModuleQuery::getInstance()->getModuleByName($sModuleName);
|
|
|
+ $aModule = BxDolModuleQuery::getInstance()->getModuleByName($sModuleName);
|
|
|
|
|
|
- $aItem = $this->getAccessObject(false)->load($this->sStoreDataUrlPublic . 'json_download_update', array(
|
|
|
- 'key' => getParam('sys_oauth_key'),
|
|
|
- 'product' => base64_encode(serialize(array(
|
|
|
- 'name' => $aModule['name'],
|
|
|
- 'version' => $aModule['version'],
|
|
|
- 'hash' => $aModule['hash'],
|
|
|
- ))),
|
|
|
- ));
|
|
|
+ $aItem = $this->getAccessObject(false)->load($this->sStoreDataUrlPublic . 'json_download_update', array(
|
|
|
+ 'key' => getParam('sys_oauth_key'),
|
|
|
+ 'product' => base64_encode(serialize(array(
|
|
|
+ 'name' => $aModule['name'],
|
|
|
+ 'version' => $aModule['version'],
|
|
|
+ 'hash' => $aModule['hash'],
|
|
|
+ ))),
|
|
|
+ ));
|
|
|
|
|
|
- return $this->downloadFileInit($aItem, array('module_name' => $sModuleName, 'auto_action' => $bAutoUpdate ? 'update' : ''));
|
|
|
+ return $this->downloadFileInit($aItem, array('module_name' => $sModuleName, 'auto_action' => $bApplyUpdate ? 'update' : ''));
|
|
|
}
|
|
|
|
|
|
protected function downloadFileInit($aItem, $aParams = array())
|
|
|
{
|
|
|
- if(empty($aItem) || !is_array($aItem))
|
|
|
- return $aItem;
|
|
|
+ if(empty($aItem) || !is_array($aItem))
|
|
|
+ return $aItem;
|
|
|
|
|
|
- //--- write ZIP archive.
|
|
|
+ //--- write ZIP archive.
|
|
|
$sFilePath = '';
|
|
|
$mixedResult = $this->performWrite($aItem, $sFilePath);
|
|
|
if($mixedResult !== true)
|
|
|
- return $mixedResult;
|
|
|
+ return $mixedResult;
|
|
|
|
|
|
- return $this->downloadFileComplete($sFilePath, $aParams);
|
|
|
+ return $this->downloadFileComplete($sFilePath, $aParams);
|
|
|
}
|
|
|
|
|
|
protected function downloadFileComplete($sFilePath, $aParams = array())
|
|
|
{
|
|
|
- $bTransient = false;
|
|
|
- if(isset($aParams['transient']) && $aParams['transient'] === true) {
|
|
|
- $bTransient = true;
|
|
|
- unset($aParams['transient']);
|
|
|
+ $bTransient = false;
|
|
|
+ if(isset($aParams['transient'])) {
|
|
|
+ $bTransient = (bool)$aParams['transient'];
|
|
|
+ unset($aParams['transient']);
|
|
|
}
|
|
|
|
|
|
- $sAutoAction = isset($aParams['auto_action']) ? $aParams['auto_action'] : '';
|
|
|
- $bAutoAction = !empty($sAutoAction);
|
|
|
+ $sAutoAction = '';
|
|
|
+ $bAutoAction = false;
|
|
|
+ if(isset($aParams['auto_action'])) {
|
|
|
+ $sAutoAction = $aParams['auto_action'];
|
|
|
+ $bAutoAction = !empty($sAutoAction);
|
|
|
+ unset($aParams['auto_action']);
|
|
|
+ }
|
|
|
|
|
|
- if(!defined('BX_DOL_CRON_EXECUTE') && !self::isRealOwner()) {
|
|
|
- if(!$this->addTransientJob(self::getNameDownloadFile($aParams['module_name']), 'download_file_complete', array($sFilePath, $aParams)))
|
|
|
- return _t('_adm_str_err_download_failed');
|
|
|
+ if(!defined('BX_DOL_CRON_EXECUTE') && !self::isRealOwner()) {
|
|
|
+ if(!$this->addTransientJob(self::getNameDownloadFile($aParams['module_name']), 'download_file_complete', array($sFilePath, array_merge($aParams, array('auto_action' => $sAutoAction)))))
|
|
|
+ return _t('_adm_str_err_download_failed');
|
|
|
|
|
|
- return array('code' => BX_DOL_STUDIO_IU_RC_SCHEDULED, 'message' => _t('_adm_str_msg_download' . ($bAutoAction ? '_and_install' : '') . '_scheduled'));
|
|
|
- }
|
|
|
+ return array('code' => BX_DOL_STUDIO_IU_RC_SCHEDULED, 'message' => _t('_adm_str_msg_download' . ($bAutoAction ? '_and_install' : '') . '_scheduled'));
|
|
|
+ }
|
|
|
|
|
|
//--- Unarchive package.
|
|
|
$sPackagePath = '';
|
|
|
@@ -425,10 +481,11 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
|
|
|
|
|
|
@unlink($sFilePath);
|
|
|
if($mixedResult !== true) {
|
|
|
- if($bTransient)
|
|
|
- $this->emailNotify($mixedResult);
|
|
|
+ $this->_oLog->write('Operation failed:', $mixedResult);
|
|
|
+ if($bTransient)
|
|
|
+ $this->emailNotify($mixedResult);
|
|
|
|
|
|
- return $mixedResult;
|
|
|
+ return $mixedResult;
|
|
|
}
|
|
|
|
|
|
//--- Copy unarchived package.
|
|
|
@@ -437,80 +494,81 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
|
|
|
|
|
|
@bx_rrmdir($sPackagePath);
|
|
|
if($mixedResult !== true) {
|
|
|
- if($bTransient)
|
|
|
- $this->emailNotify($mixedResult);
|
|
|
+ $this->_oLog->write('Operation failed:', $mixedResult);
|
|
|
+ if($bTransient)
|
|
|
+ $this->emailNotify($mixedResult);
|
|
|
|
|
|
- return $mixedResult;
|
|
|
+ return $mixedResult;
|
|
|
}
|
|
|
|
|
|
- if(!$bAutoAction)
|
|
|
- return true;
|
|
|
+ if(!$bAutoAction)
|
|
|
+ return true;
|
|
|
|
|
|
- //--- Autoinstall the downloaded package if it's needed.
|
|
|
- $aResult = $this->perform($sHomePath, $sAutoAction, $aParams);
|
|
|
- if((int)$aResult['code'] != 0) {
|
|
|
- if($bTransient)
|
|
|
- $this->emailNotify($aResult['message']);
|
|
|
+ //--- Autoinstall the downloaded package if it's needed.
|
|
|
+ $aResult = $this->perform($sHomePath, $sAutoAction, $aParams);
|
|
|
+ if((int)$aResult['code'] != 0) {
|
|
|
+ if($bTransient)
|
|
|
+ $this->emailNotify($aResult['message']);
|
|
|
|
|
|
- return $aResult['message'];
|
|
|
- }
|
|
|
+ return $aResult['message'];
|
|
|
+ }
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
protected function performWrite($aItem, &$sFilePath)
|
|
|
{
|
|
|
- $sFilePath = BX_DIRECTORY_PATH_TMP . $aItem['name'];
|
|
|
- if(file_exists($sFilePath))
|
|
|
- @unlink($sFilePath);
|
|
|
+ $sFilePath = BX_DIRECTORY_PATH_TMP . $aItem['name'];
|
|
|
+ if(file_exists($sFilePath))
|
|
|
+ @unlink($sFilePath);
|
|
|
|
|
|
- $iUmaskSave = umask(0);
|
|
|
+ $iUmaskSave = umask(0);
|
|
|
|
|
|
if(!$rHandler = fopen($sFilePath, 'w')) {
|
|
|
- umask($iUmaskSave);
|
|
|
+ umask($iUmaskSave);
|
|
|
return _t('_adm_str_err_cannot_write');
|
|
|
}
|
|
|
|
|
|
$sContent = urldecode($aItem['content']);
|
|
|
if(!fwrite($rHandler, $sContent, strlen($sContent))) {
|
|
|
- umask($iUmaskSave);
|
|
|
+ umask($iUmaskSave);
|
|
|
return _t('_adm_str_err_cannot_write');
|
|
|
}
|
|
|
|
|
|
fclose($rHandler);
|
|
|
-
|
|
|
+
|
|
|
umask($iUmaskSave);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
protected function performUnarchive($sFilePath, &$sPackagePath)
|
|
|
{
|
|
|
- if(!class_exists('ZipArchive'))
|
|
|
+ if(!class_exists('ZipArchive'))
|
|
|
return _t('_adm_str_err_zip_not_available');
|
|
|
|
|
|
- $iUmaskSave = umask(0);
|
|
|
+ $iUmaskSave = umask(0);
|
|
|
|
|
|
$oZip = new ZipArchive();
|
|
|
if($oZip->open($sFilePath) !== true) {
|
|
|
- umask($iUmaskSave);
|
|
|
+ umask($iUmaskSave);
|
|
|
return _t('_adm_str_err_cannot_unzip_package');
|
|
|
}
|
|
|
|
|
|
$sPackageFolder = '';
|
|
|
if($oZip->numFiles > 0)
|
|
|
- $sPackageFolder = $oZip->getNameIndex(0);
|
|
|
+ $sPackageFolder = $oZip->getNameIndex(0);
|
|
|
|
|
|
if(empty($sPackageFolder)) {
|
|
|
- umask($iUmaskSave);
|
|
|
- return _t('_adm_str_err_cannot_unzip_package');
|
|
|
+ umask($iUmaskSave);
|
|
|
+ return _t('_adm_str_err_cannot_unzip_package');
|
|
|
}
|
|
|
-
|
|
|
- $sPackagePath = BX_DIRECTORY_PATH_TMP . $sPackageFolder;
|
|
|
+
|
|
|
+ $sPackagePath = BX_DIRECTORY_PATH_TMP . $sPackageFolder;
|
|
|
if(file_exists($sPackagePath)) // remove existing tmp folder with the same name
|
|
|
@bx_rrmdir($sPackagePath);
|
|
|
|
|
|
if(!$oZip->extractTo(BX_DIRECTORY_PATH_TMP)) {
|
|
|
- umask($iUmaskSave);
|
|
|
+ umask($iUmaskSave);
|
|
|
return _t('_adm_str_err_cannot_unzip_package');
|
|
|
}
|
|
|
|
|
|
@@ -522,33 +580,33 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
|
|
|
|
|
|
protected function performCopy($sPackagePath, &$sHomePath)
|
|
|
{
|
|
|
- if($this->bUseFtp) {
|
|
|
- $sLogin = getParam('sys_ftp_login');
|
|
|
- $sPassword = getParam('sys_ftp_password');
|
|
|
- $sPath = getParam('sys_ftp_dir');
|
|
|
- if(empty($sLogin) || empty($sPassword) || empty($sPath))
|
|
|
- return _t('_adm_str_err_no_ftp_info');
|
|
|
-
|
|
|
- $oFile = new BxDolFtp($_SERVER['HTTP_HOST'], $sLogin, $sPassword, $sPath);
|
|
|
-
|
|
|
- if(!$oFile->connect())
|
|
|
- return _t('_adm_str_err_cannot_connect_to_ftp');
|
|
|
-
|
|
|
- if(!$oFile->isUna())
|
|
|
- return _t('_adm_str_err_destination_not_valid');
|
|
|
+ if($this->bUseFtp) {
|
|
|
+ $sLogin = getParam('sys_ftp_login');
|
|
|
+ $sPassword = getParam('sys_ftp_password');
|
|
|
+ $sPath = getParam('sys_ftp_dir');
|
|
|
+ if(empty($sLogin) || empty($sPassword) || empty($sPath))
|
|
|
+ return _t('_adm_str_err_no_ftp_info');
|
|
|
+
|
|
|
+ $oFile = new BxDolFtp($_SERVER['HTTP_HOST'], $sLogin, $sPassword, $sPath);
|
|
|
+
|
|
|
+ if(!$oFile->connect())
|
|
|
+ return _t('_adm_str_err_cannot_connect_to_ftp');
|
|
|
+
|
|
|
+ if(!$oFile->isUna())
|
|
|
+ return _t('_adm_str_err_destination_not_valid');
|
|
|
}
|
|
|
else
|
|
|
- $oFile = BxDolFile::getInstance();
|
|
|
+ $oFile = BxDolFile::getInstance();
|
|
|
|
|
|
$aConfig = self::getModuleConfig($sPackagePath . 'install/config.php');
|
|
|
if(empty($aConfig) || !is_array($aConfig) || empty($aConfig['home_dir']))
|
|
|
return _t('_adm_str_err_wrong_package_format');
|
|
|
|
|
|
- $sHomePath = $aConfig['home_dir'];
|
|
|
+ $sHomePath = $aConfig['home_dir'];
|
|
|
if(!$oFile->copy($sPackagePath, 'modules/' . $sHomePath))
|
|
|
return _t('_adm_str_err_files_copy_failed');
|
|
|
|
|
|
- return true;
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
protected function getConfigModule($sConfigPath, $aInstalled = array())
|
|
|
@@ -562,7 +620,7 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
|
|
|
$sVersion = $bInstalled ? $aInstalled['version'] : $aConfig['version'];
|
|
|
|
|
|
return array(
|
|
|
- 'type' => $aConfig['type'],
|
|
|
+ 'type' => $aConfig['type'],
|
|
|
'name' => isset($aConfig['name']) ? $aConfig['name'] : $aConfig['home_uri'],
|
|
|
'title' => bx_process_output($aConfig['title']),
|
|
|
'vendor' => $aConfig['vendor'],
|
|
|
@@ -609,7 +667,7 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
|
|
|
return $aInstalledInfo;
|
|
|
}
|
|
|
|
|
|
- private function getInstalledInfoShort()
|
|
|
+ private function getInstalledInfoShort()
|
|
|
{
|
|
|
$aModules = BxDolModuleQuery::getInstance()->getModules();
|
|
|
|
|
|
@@ -630,34 +688,34 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
|
|
|
|
|
|
private function addTransientJob($sName, $sAction, $aParams)
|
|
|
{
|
|
|
- if(BxDolCronQuery::getInstance()->addTransientJobService($sName, array('system', $sAction, $aParams, 'DolStudioInstallerUtils')))
|
|
|
- return true;
|
|
|
+ if(BxDolCronQuery::getInstance()->addTransientJobService($sName, array('system', $sAction, $aParams, 'DolStudioInstallerUtils')))
|
|
|
+ return true;
|
|
|
|
|
|
- return false;
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
private function emailNotify($sMessage)
|
|
|
{
|
|
|
sendMailTemplateSystem('t_BgOperationFailed', array (
|
|
|
- 'conclusion' => strip_tags($sMessage),
|
|
|
- ));
|
|
|
+ 'conclusion' => strip_tags($sMessage),
|
|
|
+ ));
|
|
|
}
|
|
|
|
|
|
private function emailNotifyModulesUpgrade($sResult, $aData)
|
|
|
{
|
|
|
- $oModuleQuery = BxDolModuleQuery::getInstance();
|
|
|
+ $oModuleQuery = BxDolModuleQuery::getInstance();
|
|
|
|
|
|
$sConclusion = '';
|
|
|
if(!empty($aData))
|
|
|
- foreach($aData as $sModule => $sMessage) {
|
|
|
- $aModule = $oModuleQuery->getModuleByName($sModule);
|
|
|
+ foreach($aData as $sModule => $sMessage) {
|
|
|
+ $aModule = $oModuleQuery->getModuleByName($sModule);
|
|
|
|
|
|
- $sConclusion .= _t('_sys_et_txt_body_modules_upgrade_' . $sResult, $aModule['title'], $sMessage);
|
|
|
- }
|
|
|
+ $sConclusion .= _t('_sys_et_txt_body_modules_upgrade_' . $sResult, $aModule['title'], $sMessage);
|
|
|
+ }
|
|
|
|
|
|
- sendMailTemplateSystem('t_UpgradeModules' . ucfirst($sResult), array (
|
|
|
- 'conclusion' => $sConclusion,
|
|
|
- ));
|
|
|
+ sendMailTemplateSystem('t_UpgradeModules' . ucfirst($sResult), array (
|
|
|
+ 'conclusion' => $sConclusion,
|
|
|
+ ));
|
|
|
}
|
|
|
}
|
|
|
|