1: <?php
2: /**
3: * This file contains the abstract upgrade job class.
4: *
5: * @package Setup
6: * @subpackage UpgradeJob
7: * @version SVN Revision $Rev:$
8: *
9: * @author Murat Purc <murat@purc.de>
10: * @copyright four for business AG <www.4fb.de>
11: * @license http://www.contenido.org/license/LIZENZ.txt
12: * @link http://www.4fb.de
13: * @link http://www.contenido.org
14: */
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: /**
19: * Abstract upgrade job class.
20: *
21: * @package Setup
22: * @subpackage UpgradeJob
23: */
24: abstract class cUpgradeJobAbstract {
25:
26: /**
27: * @var cDb
28: */
29: protected $_oDb;
30:
31: /**
32: * @var array
33: */
34: protected $_aCfg;
35:
36: /**
37: * @var string
38: */
39: protected $_setupType;
40:
41: /**
42: * @var string
43: */
44: protected $_version;
45:
46: /**
47: * @var cApiClient[]
48: */
49: protected static $_clients;
50:
51: /**
52: * @var cApiLanguage[]
53: */
54: protected static $_languages;
55:
56: /**
57: * @var string
58: */
59: protected static $_rootPath;
60:
61: /**
62: * @var string
63: */
64: protected static $_rootHttpPath;
65:
66: /**
67: * This must be set. 0 means this upgrade job will be executed every time.
68: * Anyhting else should be a valid CONTENIDO version. Only if the upgraded version
69: * is older than this string the job will be executed.
70: *
71: * Setting this to '4.8.18' would mean that any version lower than 4.8.18 will get the upgrade job.
72: * @var string
73: */
74: public $maxVersion = "0";
75:
76: /**
77: * Constructor, sets some properties
78: * @param cDb $db
79: * @param array $cfg Main configuration array
80: * @param array $cfgClient Clients configuration array
81: * @param version $version The CONTENIDO version which is upgraded
82: */
83: public function __construct(cDb $db, $cfg, $cfgClient, $version) {
84: $this->_version = $version;
85: $this->_oDb = $db;
86: $this->_aCfg = (is_array($cfg)) ? $cfg : $GLOBALS['cfg'];
87: $this->_aCfgClient = (is_array($cfgClient)) ? $cfg : $GLOBALS['cfgClient'];
88: $this->_setupType = $_SESSION['setuptype'];
89: // set default configuration for DB connection
90: cDb::setDefaultConfiguration($cfg['db']);
91:
92: if (!isset(self::$_rootPath)) {
93: list($rootPath, $rootHttpPath) = getSystemDirectories();
94: self::$_rootPath = $rootPath;
95: self::$_rootHttpPath = $rootHttpPath;
96: }
97:
98: if (!isset(self::$_clients)) {
99: self::$_clients = $this->_getAllClients();
100: }
101: if (!isset(self::$_languages)) {
102: self::$_languages = $this->_getAllLanguages();
103: }
104: }
105:
106: /**
107: * This function will perform the version check and execute the job if it succeeds.
108: *
109: * Do not override this.
110: */
111: final public function execute() {
112: if (version_compare($this->_version, $this->maxVersion, "<") || $this->maxVersion === "0") {
113: $this->_execute();
114: }
115: }
116:
117: /**
118: * Main function for each upgrade job. Each upgrade job has to implement this!
119: */
120: public abstract function _execute();
121:
122: /**
123: * Returns list of all available clients
124: * @return cApiClient[]
125: */
126: protected function _getAllClients() {
127: $aClients = array();
128: $oClientColl = new cApiClientCollection();
129: $oClientColl->select();
130: while (($oClient = $oClientColl->next()) !== false) {
131: $obj = clone $oClient;
132: $aClients[$obj->get('idclient')] = $obj;
133: }
134: return $aClients;
135: }
136:
137: /**
138: * Returns list of all available languages
139: * @return cApiLanguage[]
140: */
141: protected function _getAllLanguages() {
142: $aLanguages = array();
143: $oLanguageColl = new cApiLanguageCollection();
144: $oLanguageColl->select();
145: while (($oLang = $oLanguageColl->next()) !== false) {
146: $obj = clone $oLang;
147: $aLanguages[$obj->get('idlang')] = $obj;
148: }
149: return $aLanguages;
150: }
151:
152: /**
153: * Logs passed setup error, wrapper for logSetupFailure() function
154: * @param string $errorMsg
155: */
156: protected function _logError($errorMsg) {
157: $className = get_class($this);
158: logSetupFailure($className . ': ' . $errorMsg. "\n");
159: }
160: }
161: