first commit
This commit is contained in:
358
apps/update/modules/stInstallerWeb/lib/stChangelog.class.php
Normal file
358
apps/update/modules/stInstallerWeb/lib/stChangelog.class.php
Normal file
@@ -0,0 +1,358 @@
|
||||
<?php
|
||||
/**
|
||||
* Changelog class
|
||||
* Checking system befora installation
|
||||
*
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Changlog
|
||||
*/
|
||||
class stChangelog
|
||||
{
|
||||
/**
|
||||
* @var bool List of changelog.yml files in install/src
|
||||
*/
|
||||
var $changelog_files=NULL;
|
||||
|
||||
/**
|
||||
* @var bool true if templates smarty are changed
|
||||
* Method smartyTemplatesChanged is defined in changelog.yml
|
||||
*/
|
||||
var $smarty_changed=false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
$this->apps_new = $this->readSyncUpgrades();
|
||||
$this->apps_pear = $this->readPearUpgrades();
|
||||
$this->files = $this->readAllFiles();
|
||||
$this->active_contents = $this->readActiveContents();
|
||||
}
|
||||
|
||||
/**
|
||||
* get all changelog files
|
||||
*/
|
||||
protected function readAllFiles()
|
||||
{
|
||||
$install_dir=sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'src';
|
||||
$apps=$this->getSyncUpgrades();
|
||||
$files=array();
|
||||
|
||||
foreach ($apps as $app)
|
||||
{
|
||||
$file = $install_dir.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.'packages'.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.'changelog.yml';
|
||||
if (file_exists($file))
|
||||
{
|
||||
$files[$app]=$file;
|
||||
}
|
||||
}
|
||||
if (! empty($files)) return $files;
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all changelog.yml files
|
||||
*/
|
||||
public function getAllFiles()
|
||||
{
|
||||
return $this->files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read sync list
|
||||
* @return arra return
|
||||
*/
|
||||
protected function readPearUpgrades() {
|
||||
$result = array();
|
||||
$newPackages = $this->getSyncUpgrades();
|
||||
|
||||
foreach (stPear::getInstalledPackages() as $package => $version)
|
||||
if (in_array($package, $newPackages))
|
||||
$result[$package] = $version;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pear list
|
||||
* @return array
|
||||
*/
|
||||
public function getPearUpgrades()
|
||||
{
|
||||
return $this->apps_pear;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PEAR version for the app
|
||||
*
|
||||
* @param string $app Application
|
||||
* @return string Version
|
||||
*/
|
||||
protected function getPearVersion($app)
|
||||
{
|
||||
if (! empty($this->apps_pear[$app])) return $this->apps_pear[$app];
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read sync list
|
||||
* @return arra return
|
||||
*/
|
||||
protected function readSyncUpgrades()
|
||||
{
|
||||
$regsync = new stRegisterSync();
|
||||
$apps_sync=$regsync->getAppsToSync();
|
||||
|
||||
if (! empty($apps_sync['all']))
|
||||
{
|
||||
return $apps_sync['all'];
|
||||
} else return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sync list
|
||||
* @return array
|
||||
*/
|
||||
public function getSyncUpgrades()
|
||||
{
|
||||
return $this->apps_new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there ary any changelog information in install/src, active
|
||||
* @return bool
|
||||
*/
|
||||
public function isAnyActive()
|
||||
{
|
||||
if (! empty($this->active_contents)) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return information if smarty templates were changed
|
||||
* @return bool true - changed, false - not
|
||||
*/
|
||||
public function isSmartyChanged()
|
||||
{
|
||||
if ($this->smarty_changed) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get smarty theme
|
||||
* @return string Theme name
|
||||
*/
|
||||
public function getSmartyTheme()
|
||||
{
|
||||
if (! empty($this->smarty_theme)) return $this->smarty_theme;
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is any active change log for sync apps and current PEAR apps versions
|
||||
* @return array() list of active files
|
||||
*/
|
||||
protected function readActiveContents()
|
||||
{
|
||||
$contents = $this->getContents();
|
||||
$contents_active=array();
|
||||
|
||||
$this->smarty_changed=false;
|
||||
|
||||
// echo "<pre>app_content:";print_r($contents);echo "</pre>";
|
||||
|
||||
if (! empty($contents))
|
||||
{
|
||||
foreach ($contents as $app=>$contents_app)
|
||||
{
|
||||
foreach ($contents_app['changelog'] as $keyname=>$content)
|
||||
{
|
||||
$add_version=0; $add_method=0;
|
||||
if (! empty($content['version']))
|
||||
{
|
||||
// echo "<pre>version: ";print_r($content['changelog']['version']);echo "</pre>";
|
||||
if ($this->checkVersion($app,$content['version']))
|
||||
{
|
||||
$add_version=1;
|
||||
} else
|
||||
{
|
||||
return $contents_active;
|
||||
}
|
||||
}
|
||||
|
||||
// echo "<pre>";print_r($contents_app);echo "</pre>";
|
||||
|
||||
if ((! empty($content['method']['name'])) && ($add_version==1))
|
||||
{
|
||||
|
||||
// echo "<pre>method: ";print_r($content['changelog']['method']['name']);echo "</pre>";
|
||||
// $myobject = new stChangelogFunctions();
|
||||
$method=$content['method']['name'];
|
||||
|
||||
if (! empty($content['method']['params']))
|
||||
{
|
||||
$params=$content['method']['params'];
|
||||
} else $params=array();
|
||||
|
||||
if (! empty($content['priority']))
|
||||
{
|
||||
$priority=$content['priority'];
|
||||
} else $priority=5; // 1 - important , 5 - minor changes
|
||||
|
||||
// $result=call_user_func(array($myobject, $method), $params);
|
||||
|
||||
$this->call_ret=call_user_func_array (array('stChangelogFunctions', $method), array($app,$params,'condition'));
|
||||
if (! empty($this->call_ret['result']))
|
||||
{
|
||||
$this->result['P'.$priority][$app][$keyname]['data'] = $this->call_ret['result'];
|
||||
$this->result['P'.$priority][$app][$keyname]['method'] = $method;
|
||||
|
||||
// there yopu can add more information from changelog.yml for template
|
||||
// $this->result['P'.$priority][$app][$keyname]['keyname_params']['yourkey'] = value
|
||||
$this->result['P'.$priority][$app][$keyname]['keyname_params']['url'] = $content['url'];
|
||||
|
||||
}
|
||||
// echo "<pre>app=$app :";print_r($result);echo "</pre>";
|
||||
if ($this->call_ret['return'])
|
||||
{
|
||||
// addidtional info for smarty method
|
||||
if ($method=='smartyTemplatesChanged')
|
||||
{
|
||||
$this->smarty_changed=true;
|
||||
$this->smarty_theme=$this->call_ret['theme'];
|
||||
}
|
||||
$add_method=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (($add_version==1) && ($add_method==1)) $contents_active[$app]=$content;
|
||||
}
|
||||
}
|
||||
|
||||
return $contents_active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get changelog function result
|
||||
* @see stChangelogFunctions class
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResult()
|
||||
{
|
||||
|
||||
if (! empty($this->result))
|
||||
{
|
||||
ksort($this->result,SORT_STRING);
|
||||
return $this->result;
|
||||
}
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get changelog content
|
||||
* @param string $app Applikaction
|
||||
* @param array $content Content data
|
||||
* @param string $priority (P1|P2|P3|P4|P5)
|
||||
* @return string HTML
|
||||
*/
|
||||
public function getUpdateContent($app,$app_content,$priority)
|
||||
{
|
||||
|
||||
$culture=sfContext::getInstance()->getUser()->getCulture();
|
||||
|
||||
$result=array();
|
||||
foreach ($app_content as $keyname=>$data_array)
|
||||
{
|
||||
|
||||
$params=$data_array['data'];
|
||||
$method=$data_array['method'];
|
||||
$keyname_params = $data_array['keyname_params'];
|
||||
if (! empty($keyname_params['url'])) $url=$keyname_params['url']; else $url=NULL;
|
||||
|
||||
$file=sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.'changelog'.DIRECTORY_SEPARATOR.$culture.DIRECTORY_SEPARATOR.$keyname.'.html';
|
||||
if (file_exists($file))
|
||||
{
|
||||
// execute method for keyname
|
||||
$file=file_get_contents($file);
|
||||
} else $file='';
|
||||
$ret_keyname=call_user_func_array (array('stChangelogFunctions', $method), array($app,$params,'runkeyname',$keyname_params));
|
||||
|
||||
$result['keyname'][$keyname]['content']=$file.$ret_keyname;
|
||||
$result['keyname'][$keyname]['url']=$url;
|
||||
}
|
||||
|
||||
// execute method for app
|
||||
$ret_app=call_user_func_array (array('stChangelogFunctions', $method), array($app,$params,'runapp'));
|
||||
$result['resume']=$ret_app;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get active changelog content arrays
|
||||
* @return array
|
||||
*/
|
||||
public function getActiveContents()
|
||||
{
|
||||
return $this->active_contents;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if version is active. Compare versions.
|
||||
* @param string $app Application
|
||||
* @param array $version Version
|
||||
* @return bool
|
||||
*/
|
||||
protected function checkVersion($app,$version)
|
||||
{
|
||||
$min = NULL;
|
||||
$max = NULL;
|
||||
if (! empty($version['min'])) $min=$version['min'];
|
||||
if (! empty($version['max'])) $max=$version['max'];
|
||||
|
||||
/**
|
||||
* Fixed: Package version is from package.yml not from pear.
|
||||
* @author Michal Prochowski <michal.prochowski@sote.pl>
|
||||
*/
|
||||
// $pearv = $this->getPearVersion($app);// app PEAR version
|
||||
$packageFile = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'packages'.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.'package.yml';
|
||||
if (file_exists($packageFile)) {
|
||||
$package = sfYaml::load($packageFile);
|
||||
$pearv = $package['package']['version'];
|
||||
} else {
|
||||
$pearv = 0;
|
||||
}
|
||||
// echo "pearv=$pearv min=$min max=$max <br>";
|
||||
|
||||
if (! empty($pearv))
|
||||
{
|
||||
if ((version_compare($pearv,$min,'>=')) && (version_compare($pearv,$max,'<=')))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function getContents()
|
||||
{
|
||||
$content=array();
|
||||
$files=$this->getAllFiles();
|
||||
if (! empty($files))
|
||||
{
|
||||
foreach ($files as $app=>$file)
|
||||
{
|
||||
$content[$app]=sfYaml::load($file);
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Base class for Changelog update classes
|
||||
*
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Changelog base class
|
||||
*/
|
||||
class stChangelogBase
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Changelog Description class
|
||||
*
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Changelog Description
|
||||
*/
|
||||
class stChangelogDescription extends stChangelogBase
|
||||
{
|
||||
/**
|
||||
* Instance
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* Singleton
|
||||
*
|
||||
* @param stBackendDesktop $base_class
|
||||
* @return stBackendDesktop
|
||||
*/
|
||||
public static function getInstance($base_class = null)
|
||||
{
|
||||
if (null === self::$instance)
|
||||
{
|
||||
if (null === $base_class)
|
||||
{
|
||||
$base_class = __CLASS__;
|
||||
}
|
||||
|
||||
self::$instance = new $base_class();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Condition
|
||||
*
|
||||
* @param string $app Application
|
||||
* @param mixed $params Parameters
|
||||
* @return array('return'=>bool,'result'=>mixed)
|
||||
*/
|
||||
public function condition($app,$params)
|
||||
{
|
||||
return array('return'=>true, 'result'=>array(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional description for 1 update for 1 app
|
||||
* @param mixe $params result from stChangelogDescription::execute['result']
|
||||
* @return string HTML
|
||||
*/
|
||||
public function runkeyname($app,$params,$keyname_params)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional description for all updates for 1 app
|
||||
* @param mixed $params result from stChangelogDescription::execute['result']
|
||||
* @return array Unique files for app
|
||||
*/
|
||||
public function runapp($app,$params)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* Changelog function class
|
||||
*
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Changelog
|
||||
*/
|
||||
class stChangelogFunctions
|
||||
{
|
||||
var $result=false;
|
||||
|
||||
/**
|
||||
* Smarty templatecs changed.
|
||||
*
|
||||
* @param array $params
|
||||
* @param string $mode execute|content
|
||||
* @return mixed
|
||||
*/
|
||||
public function smartyTemplatesChanged($app,$params,$method='condition',$keyname_params=NULL)
|
||||
{
|
||||
|
||||
$smarty_changelog = stChangelogSmarty::getInstance();
|
||||
switch ($method)
|
||||
{
|
||||
case 'condition': return $smarty_changelog->condition($app,$params); break;
|
||||
case 'runkeyname': return $smarty_changelog->runkeyname($app,$params,$keyname_params); break;
|
||||
case 'runapp': return $smarty_changelog->runapp($app,$params); break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description for changes
|
||||
*
|
||||
* @param array $params
|
||||
* @param string $mode execute|content
|
||||
* @return mixed
|
||||
*/
|
||||
public function description($app,$params,$method='condition',$keyname_params)
|
||||
{
|
||||
$description = stChangelogDescription::getInstance();
|
||||
switch ($method)
|
||||
{
|
||||
case 'condition': return $description->condition($app,$params); break;
|
||||
case 'runkeyname': return $description->runkeyname($app,$params,$keyname_params); break;
|
||||
case 'runapp': return NULL; break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
/**
|
||||
* Changelog Smarty class
|
||||
*
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Changelog
|
||||
*/
|
||||
class stChangelogSmarty extends stChangelogBase
|
||||
{
|
||||
/**
|
||||
* @var string unique changed smarty files
|
||||
*/
|
||||
var $files=array();
|
||||
|
||||
/**
|
||||
* Instance
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* Singleton
|
||||
*
|
||||
* @return stChangeLogSmarty
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
$base_class = __CLASS__;
|
||||
if (null === self::$instance) self::$instance = new $base_class();
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty templatecs changed, detect and remember data
|
||||
*
|
||||
* @param string $app Application
|
||||
* @param mixed $params Parameters
|
||||
* @return array('return'=>bool,'result'=>mixed)
|
||||
*/
|
||||
public function condition($app,$params)
|
||||
{
|
||||
$exists=0;
|
||||
|
||||
// get default theme
|
||||
$databaseManager = new sfDatabaseManager();
|
||||
$databaseManager->initialize();
|
||||
$path = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.'frontend'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'soteshop.yml';
|
||||
$config = sfYaml::load($path);
|
||||
$developerTheme = $config['all']['.view']['theme'];
|
||||
if (! $developerTheme)
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->add(ThemePeer::ACTIVE, 1);
|
||||
$theme_object = ThemePeer::doSelectOne($c);
|
||||
$theme = $theme_object->getTheme();
|
||||
}
|
||||
else $theme = $developerTheme;
|
||||
$databaseManager->shutdown();
|
||||
// end
|
||||
|
||||
// ignore default theme names
|
||||
if (($theme == 'default') || ($theme=='default2') || ($theme == 'homeelectronics'))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (empty($params['files'])) return true;
|
||||
|
||||
$files = $params['files'];
|
||||
$mytheme_files=array();
|
||||
foreach ($files as $id=>$file)
|
||||
{
|
||||
$file=preg_replace("/\[MY_THEME\]/",$theme,$file);
|
||||
$path=sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.$file;
|
||||
if (file_exists($path))
|
||||
{
|
||||
$exists=1;
|
||||
$mytheme_files[]=$file;
|
||||
}
|
||||
}
|
||||
|
||||
if ($exists==1) return array('return'=>true,'result'=>$mytheme_files,'theme'=>$theme);
|
||||
else return array('return'=>false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remember unique files for each changelog keyname for app
|
||||
* @param mixed $params result from stChangelogSmarty::execute['result']
|
||||
* @return string HTML
|
||||
*/
|
||||
public function runkeyname($app,$params)
|
||||
{
|
||||
foreach ($params as $id=>$filename)
|
||||
{
|
||||
$this->files[$app][$filename]=1;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all changed files for app.
|
||||
* @param mixed $params result from stChangelogSmarty::execute['result']
|
||||
* @return array Unique files for app
|
||||
*/
|
||||
public function runapp($app,$params)
|
||||
{
|
||||
$i18n = sfContext::getInstance()->getI18N();
|
||||
if (! empty($this->files[$app]))
|
||||
{
|
||||
$content='';
|
||||
$content.="<p />";
|
||||
$content.="<b>".$i18n->__('Pliki:')."</b>";
|
||||
$content.="<ul>\n";
|
||||
foreach ($this->files[$app] as $filename=>$tmp)
|
||||
{
|
||||
if (strlen($filename)>96)
|
||||
{
|
||||
$max=96;
|
||||
$f1=substr($filename,0,$max);
|
||||
$f2=substr($filename,$max,strlen($filename)-$max);
|
||||
$filename=$f1.' -<br /> - '.$f2;
|
||||
}
|
||||
$content.="<li>$filename</li>\n";
|
||||
}
|
||||
$content.="</ul>\n";
|
||||
|
||||
return $content;
|
||||
} else return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Backup files
|
||||
* @return string token for backup
|
||||
*/
|
||||
public function doBackup()
|
||||
{
|
||||
// backup $this->files
|
||||
$files_all=array();
|
||||
foreach ($this->files as $app=>$files)
|
||||
{
|
||||
$files_all=array_merge($files,$files_all);
|
||||
}
|
||||
|
||||
$files_list=array();
|
||||
foreach ($files_all as $file=>$tmp)
|
||||
{
|
||||
$files_list[]=$file;
|
||||
}
|
||||
$backup = stUpdateBackup::getInstance();
|
||||
$token=$backup->doBackup($files_list);
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all changed files for all app.
|
||||
* @return array Unique files for app
|
||||
*/
|
||||
public function getAllFiles()
|
||||
{
|
||||
$result=array();
|
||||
if (! empty($this->files))
|
||||
{
|
||||
|
||||
foreach ($this->files as $app=>$files)
|
||||
{
|
||||
foreach ($files as $filename=>$tmp)
|
||||
{
|
||||
$result[]=$filename;
|
||||
}
|
||||
}
|
||||
} else $result=NULL;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
class stCheckBrowser {
|
||||
public static function check() {
|
||||
$stWebRequest = new stWebRequest();
|
||||
$httpUserAgent = $stWebRequest->getHttpUserAgent();
|
||||
|
||||
if (!preg_match('/MSIE 6\.0/', $httpUserAgent) && !preg_match('/MSIE 7\.0/', $httpUserAgent))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
class stCheckTheme {
|
||||
|
||||
public static function check() {
|
||||
$config = sfYaml::load(sfConfig::get('sf_root_dir').'/config/databases.yml');
|
||||
$c = $config['all']['propel']['param'];
|
||||
|
||||
try {
|
||||
$pdo = new PDO('mysql:dbname='.$c['database'].';host='.$c['host'], $c['username'], $c['password']);
|
||||
|
||||
$sth = $pdo->prepare('SELECT COUNT(`id`) as `count` FROM `st_theme` WHERE `active` = 1 AND (`version` < 2 OR `version` IS NULL);');
|
||||
$sth->execute();
|
||||
$result = $sth->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if(isset($result['count']))
|
||||
return !(int) $result['count'];
|
||||
else
|
||||
return false;
|
||||
} catch (PDOException $e) {
|
||||
return -1;
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stUpdate
|
||||
*
|
||||
* This file is the part of stUpdate application. License: (Open License SOTE) Open License SOTE.
|
||||
* Do not modify this file, system will overwrite it during upgrade.
|
||||
*
|
||||
* @package stUpdate
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Open License SOTE
|
||||
* @version $Id: stInstallerFrontendWeb.class.php 4621 2010-04-19 17:06:15Z marek $
|
||||
*/
|
||||
|
||||
/**
|
||||
* PEAR base classes
|
||||
* @todo add PEAR.php verification (eg. for Windows installation), check include_path
|
||||
*/
|
||||
error_reporting(($errorsCode = error_reporting()) & ~E_STRICT);
|
||||
|
||||
require_once 'PEAR.php';
|
||||
require_once 'PEAR/Frontend.php';
|
||||
require_once 'PEAR/Command.php';
|
||||
require_once 'PEAR/Config.php';
|
||||
require_once 'PEAR/Registry.php';
|
||||
require_once 'PEAR/Frontend/CLI.php';
|
||||
|
||||
error_reporting($errorsCode);
|
||||
|
||||
/**
|
||||
* PEAR Frontend Web class
|
||||
*/
|
||||
require_once (__DIR__.'/stPearFrontendWeb.class.php');
|
||||
|
||||
|
||||
/**
|
||||
* Installer Frontend Web
|
||||
*
|
||||
* @package stUpdate
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stInstallerFrontendWeb
|
||||
{
|
||||
/**
|
||||
* @var string Error messages.
|
||||
*/
|
||||
var $error='';
|
||||
|
||||
/**
|
||||
* @var stPearFrontendWeb PEAR Frontend.
|
||||
*/
|
||||
var $ui;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param string $pear_user_config path to .pearrc file (install/src/.pearrc)
|
||||
* @return bool
|
||||
*/
|
||||
function __construct($pear_user_config='')
|
||||
{
|
||||
|
||||
// PEAR Config file
|
||||
if (empty($pear_user_config)) $pear_user_config=sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'.pearrc';
|
||||
|
||||
// Init PEAR configuration
|
||||
// @see PEAR_Frontend_Web PEAR/Frontend/Web.php
|
||||
$GLOBALS['_PEAR_Frontend_Web_config'] = PEAR_Config::singleton($pear_user_config, $pear_user_config);
|
||||
$this->config = $GLOBALS['_PEAR_Frontend_Web_config'];
|
||||
if (PEAR::isError($this->config)) {
|
||||
throw new Exception('<b>Error:</b> '.$this->config->getMessage());
|
||||
}
|
||||
// end
|
||||
|
||||
// Init PEAR Frontend class
|
||||
// PEAR_Frontend::setFrontendClass('PEAR_Frontend_CLI');
|
||||
$this->ui = PEAR_Frontend::setFrontendClass('stPearFrontendWeb');
|
||||
PEAR_Frontend::setFrontendObject($this->ui);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute PEAR command.
|
||||
*
|
||||
* @param string $command PEAR command eg. 'install'
|
||||
* @param array $params parameters np. array('pear.dev.quad.sote.pl/stApplicationTest')
|
||||
* @param array $opts options np. array('force'=>false,...)
|
||||
* @return bool
|
||||
*/
|
||||
public function command($command,$params=array(),$opts=array())
|
||||
{
|
||||
if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) $timer = sfTimerManager::getTimer('__SOTE executeUpgradeList stInstallerFrontendWeb::command('.$command.')');
|
||||
if (($command=='install') && (! sizeof($opts)))
|
||||
{
|
||||
$opts['onlyreqdeps'] = true;
|
||||
$opts['force'] = false;
|
||||
}
|
||||
|
||||
// install force (eg. upload action)
|
||||
if ($command=='force-install')
|
||||
{
|
||||
$command='install';
|
||||
$opts['force'] = true;
|
||||
}
|
||||
|
||||
$cmd = PEAR_Command::factory($command, $this->config);
|
||||
|
||||
if (PEAR::isError($cmd))
|
||||
{
|
||||
$this->error=$cmd->getMessage();
|
||||
} else
|
||||
{
|
||||
// execute PEAR command
|
||||
$ok = $cmd->run($command, $opts, $params);
|
||||
|
||||
if (PEAR::isError($ok)) {
|
||||
$this->error=$ok->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) $timer->addTime();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Errors.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getErrors()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
/**
|
||||
* SOTESHOP/stUpdate
|
||||
*
|
||||
* This file is the part of stUpdate application. License: (Open License SOTE) Open License SOTE.
|
||||
* Do not modify this file, system will overwrite it during upgrade.
|
||||
*
|
||||
* @package stUpdate
|
||||
* @subpackage libs
|
||||
* @copyright SOTE (www.sote.pl)
|
||||
* @license http://www.sote.pl/license/open (Open License SOTE) Open License SOTE
|
||||
* @version $Id: stPearFrontendWeb.class.php 11065 2011-02-16 10:38:27Z marek $
|
||||
*/
|
||||
|
||||
/**
|
||||
* PEAR Frontend Web.
|
||||
*
|
||||
* @author Marek jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*
|
||||
* @package stUpdate
|
||||
* @subpackage libs
|
||||
*/
|
||||
class stPearFrontendWeb extends PEAR_Frontend_CLI
|
||||
{
|
||||
|
||||
|
||||
public function PEAR_Frontend_Web()
|
||||
{
|
||||
parent::PEAR();
|
||||
$this->config = &$GLOBALS['_PEAR_Frontend_Web_config'];
|
||||
}
|
||||
|
||||
function setConfig(&$config)
|
||||
{
|
||||
$this->config = &$config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display human-friendly output formatted depending on the
|
||||
* $command parameter.
|
||||
* This should be able to handle basic output data with no command
|
||||
* @abstract
|
||||
*
|
||||
* @param mixed $data data structure containing the information to display
|
||||
* @param string $command command from which this method was called
|
||||
*/
|
||||
public function outputData($data, $command = '_default')
|
||||
{
|
||||
switch ($command)
|
||||
{
|
||||
case "list":
|
||||
$this->_list($data);
|
||||
break;
|
||||
case "list-upgrades":
|
||||
$this->_listUpgrades($data);
|
||||
break;
|
||||
case "install":
|
||||
$this->_install($data);
|
||||
stPearCache::removeCache();
|
||||
break;
|
||||
case "upgrade":
|
||||
$this->_upgrade($data);
|
||||
stPearCache::removeCache();
|
||||
break;
|
||||
case "clear-cache":
|
||||
stPearCache::removeCache();
|
||||
break;
|
||||
default:
|
||||
$this->_default($data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show application list.
|
||||
*
|
||||
* @param array
|
||||
* @return STDOUT
|
||||
*/
|
||||
private function _list($data)
|
||||
{
|
||||
if (! empty($data['data'])) {
|
||||
$list=array();
|
||||
|
||||
foreach ($data['data'] as $key=>$app)
|
||||
{
|
||||
$name=$app[0];
|
||||
$version=$app[1];
|
||||
$list[$name]=$version;
|
||||
}
|
||||
// show template
|
||||
// include_once (ST_TMPL_PEAR.'pear_list.php');
|
||||
$this->printResult(serialize($list));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show messages after installation.
|
||||
*
|
||||
* @param array
|
||||
* @return STDOUT
|
||||
*/
|
||||
private function _install($data)
|
||||
{
|
||||
$this->printResult(serialize(array($data)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show list upgrades.
|
||||
*
|
||||
* @param array
|
||||
*/
|
||||
private function _listUpgrades($data)
|
||||
{
|
||||
if (! empty($data['data'])) {
|
||||
$list=array();
|
||||
|
||||
foreach ($data['data'] as $key=>$app)
|
||||
{
|
||||
$channel=$app[0];
|
||||
$name=$app[1];
|
||||
$version=$app[3];
|
||||
$size=$app[4];
|
||||
$list[]=array('channel'=>$channel,'name'=>$name,'version'=>$version,'size'=>$size);
|
||||
}
|
||||
// wyswietl szablon
|
||||
$this->printResult(serialize($list));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show upgrade result.
|
||||
*
|
||||
* @param mixed
|
||||
* @return STDOUT string
|
||||
*/
|
||||
private function _upgrade($data)
|
||||
{
|
||||
$this->printResult($data['data']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show PEAR messages.
|
||||
*
|
||||
* @param string $data
|
||||
* @return STDOUT
|
||||
*/
|
||||
private function _default($data)
|
||||
{
|
||||
$this->printResult(serialize($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return printed data.
|
||||
*
|
||||
* @param string $data
|
||||
* @return STDOUT
|
||||
*/
|
||||
private function printResult($data)
|
||||
{
|
||||
print "<PEAR_RESULT>".$data."</PEAR_RESULT>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data from $this->print()
|
||||
*
|
||||
* @param string $data PEAR_RESULT
|
||||
* @param string $mode unserialize|raw
|
||||
* @return string | serialized string | NULL
|
||||
*/
|
||||
static public function getPearResult($data, $mode = 'unserialize') {
|
||||
$data = preg_replace('/<\/*PEAR_RESULT>/', '', $data);
|
||||
if (!empty($data)) {
|
||||
if ($mode == 'unserialize') {
|
||||
$arrayData = @unserialize($data);
|
||||
if (is_array($arrayData))
|
||||
return $arrayData;
|
||||
else
|
||||
return $data;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Class with methods executed before install
|
||||
*
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Pre install class
|
||||
*/
|
||||
class stPreInstall
|
||||
{
|
||||
/**
|
||||
* @var string install dir
|
||||
*/
|
||||
var $install_dir;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->install_dir = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'src';
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all packages with package/stAppName/preinstall.yml files
|
||||
*
|
||||
* @return array array(stAppName1, stAppName2, ...)
|
||||
*/
|
||||
public function getApps()
|
||||
{
|
||||
$dirs=sfFinder::type('dir')->maxdepth(0)->relative()->in($this->install_dir);
|
||||
$apps=array();
|
||||
foreach ($dirs as $dir)
|
||||
{
|
||||
$preinstall_yml = $this->getPreinstallConfigPath($dir);
|
||||
if(file_exists($preinstall_yml))
|
||||
{
|
||||
$apps[]=$dir;
|
||||
}
|
||||
}
|
||||
|
||||
return $apps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returnt path to config file for app
|
||||
*
|
||||
* @param string $app
|
||||
* @return string
|
||||
*/
|
||||
private function getPreinstallConfigPath($app)
|
||||
{
|
||||
return $this->install_dir.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.'packages'.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.'preinstall.yml';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get config for app
|
||||
*
|
||||
* @param string
|
||||
*/
|
||||
public function getConfig($app)
|
||||
{
|
||||
$data = sfYaml::load($this->getPreinstallConfigPath($app));
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
211
apps/update/modules/stInstallerWeb/lib/stUpdateBackup.class.php
Normal file
211
apps/update/modules/stInstallerWeb/lib/stUpdateBackup.class.php
Normal file
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
/**
|
||||
* Update backup
|
||||
* @author Marek Jakubowicz <marek.jakubowicz@sote.pl>
|
||||
*/
|
||||
|
||||
/**
|
||||
* PEAR Tar library
|
||||
*/
|
||||
require_once('Archive/Tar.php');
|
||||
|
||||
/**
|
||||
* Update backup
|
||||
*/
|
||||
class stUpdateBackup
|
||||
{
|
||||
/**
|
||||
* Instance
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* Singleton
|
||||
*
|
||||
* @param string $base_class
|
||||
* @return stUpdateBackup
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
$base_class = __CLASS__;
|
||||
if (null === self::$instance) self::$instance = new $base_class();
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get backup Token ID
|
||||
*/
|
||||
protected function getToken($files)
|
||||
{
|
||||
$md5_sign=NULL;
|
||||
if (! empty($this->token)) return $this->token;
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$file_path=sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.$file;
|
||||
if (file_exists($file_path))
|
||||
{
|
||||
$data=file_get_contents($file_path);
|
||||
$md5_data=md5($data);
|
||||
|
||||
$md5sign=md5($md5sign.$md5_data);
|
||||
unset($data);
|
||||
}
|
||||
}
|
||||
|
||||
$this->token=$md5sign;
|
||||
|
||||
if (empty($this->token)) throw new Exception("Empty backup token");
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create report file
|
||||
* @param array $files
|
||||
*/
|
||||
protected function createReport($files)
|
||||
{
|
||||
$report='';
|
||||
$report.="Date: ".date('Y/m/d H:i:s')."\n";
|
||||
$report.="IP: ".$_SERVER['REMOTE_ADDR']."\n";
|
||||
$report.="\n";
|
||||
$report.="Files:\n";
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$file_path=sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.$file;
|
||||
if (file_exists($file_path))
|
||||
{
|
||||
$data=file_get_contents($file_path);
|
||||
$md5=md5($data);
|
||||
unset($data);
|
||||
} else $md5='not found';
|
||||
$report.= " - $file \tmd5: $md5\n";
|
||||
}
|
||||
file_put_contents($this->getDir().DIRECTORY_SEPARATOR.'report.txt',$report);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get backup dir
|
||||
* @param string $token
|
||||
* @return string backup dir
|
||||
*/
|
||||
protected function getDir($token=NULL)
|
||||
{
|
||||
if (! empty($this->backup_dir)) return $this->backup_dir;
|
||||
|
||||
$dir=sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'backups'.DIRECTORY_SEPARATOR.$token;
|
||||
if (! is_dir($dir))
|
||||
{
|
||||
if (! mkdir($dir)) throw new Exception("Unable mkdir $dir");
|
||||
}
|
||||
$this->backup_dir=$dir;
|
||||
return $this->backup_dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get backup file
|
||||
* @param string $token
|
||||
* @return string
|
||||
*/
|
||||
public function getBackupFile($token)
|
||||
{
|
||||
$file='backups'.DIRECTORY_SEPARATOR.$token.DIRECTORY_SEPARATOR.'backup-'.$token.'.tgz';
|
||||
return $file;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Backup files
|
||||
* @param array $files
|
||||
* @return string token
|
||||
*/
|
||||
public function doBackup($files)
|
||||
{
|
||||
|
||||
$token=$this->getToken($files);
|
||||
$backup_dir=$this->getDir($token);
|
||||
$backup_files_arch=array();
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$from=sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.$file;
|
||||
$tdir=$backup_dir;
|
||||
$to=$tdir.DIRECTORY_SEPARATOR.$file;
|
||||
$dirs=preg_split('/\//',dirname($file));
|
||||
foreach ($dirs as $d)
|
||||
{
|
||||
$tdir.=DIRECTORY_SEPARATOR.$d;
|
||||
// echo "tdir=$tdir $d <br>";
|
||||
if (! is_dir($tdir))
|
||||
{
|
||||
if (! mkdir($tdir)) throw new Exception("Unable mkdir $tdir");
|
||||
}
|
||||
}
|
||||
|
||||
if (! copy($from,$to)) throw new Exception("Unable copy $from $to");
|
||||
$backup_files_arch[]=$from;
|
||||
}
|
||||
|
||||
// create report file in backup dir
|
||||
$this->createReport($files);
|
||||
|
||||
$dest_package = $backup_dir.DIRECTORY_SEPARATOR.basename($this->getBackupFile($token));
|
||||
$compress = true;
|
||||
$arch_files = sfFinder::type('file')->name('*')->relative()->discard(basename($dest_package))->in($backup_dir);
|
||||
|
||||
$cwd=getcwd();chdir($backup_dir);
|
||||
$tar = new Archive_Tar($dest_package, $compress);
|
||||
$tar->create($arch_files);
|
||||
chdir($cwd);
|
||||
$this->saveLastBackupInformation($backup_files_arch,$token);
|
||||
|
||||
return $this->getToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save last backup information
|
||||
* @param array $files
|
||||
* @param strtong $token
|
||||
* @return true;
|
||||
*/
|
||||
protected function saveLastBackupInformation($files,$token)
|
||||
{
|
||||
$path = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'db'.DIRECTORY_SEPARATOR.'.last_backup.reg';
|
||||
$data=array("data"=>$files,"token"=>$token);
|
||||
if (! file_put_contents($path, serialize($data))) throw new Exception("Unable save backup information in ".$path);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove archived files
|
||||
*/
|
||||
static public function cleanBackup()
|
||||
{
|
||||
$path = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'install'.DIRECTORY_SEPARATOR.'db'.DIRECTORY_SEPARATOR.'.last_backup.reg';
|
||||
if (file_exists($path))
|
||||
{
|
||||
$data_raw=file_get_contents($path);
|
||||
$data=unserialize($data_raw);
|
||||
if (is_array($data))
|
||||
{
|
||||
if ((isset($data['data'])) && (isset($data['token'])))
|
||||
{
|
||||
if (! empty($data['token'])) $token=$data['token']; else $token=NULL;
|
||||
if (is_array($data['data']))
|
||||
{
|
||||
foreach ($data['data'] as $file)
|
||||
{
|
||||
if (file_exists($file))
|
||||
{
|
||||
if (! unlink($file)) throw new Exception ("Unable delete file $file. Backup token: $token");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
throw new Exception("Wrong serialized data in $path. Undefined array keys 'data' or 'token'. Check backup. Token: $token");
|
||||
}
|
||||
} else throw new Exception("Wrong serialized data in $path. Check backup. Token: $token");
|
||||
}
|
||||
if (file_exists($path)) unlink ($path);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user