Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  1: <?php
  2: /**
  3:  * This file contains the module synchronizer class.
  4:  * TODO: Rework comments of this class.
  5:  *
  6:  * @package    Core
  7:  * @subpackage Backend
  8:  * @version    SVN Revision $Rev:$
  9:  *
 10:  * @author     Rusmir Jusufovic
 11:  * @copyright  four for business AG <www.4fb.de>
 12:  * @license    http://www.contenido.org/license/LIZENZ.txt
 13:  * @link       http://www.4fb.de
 14:  * @link       http://www.contenido.org
 15:  */
 16: 
 17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 18: 
 19: cInclude('includes', 'functions.api.string.php');
 20: cInclude('includes', 'functions.con.php');
 21: 
 22: /**
 23:  * This class synchronized the contents of modul dir with the table
 24:  * $cfg['tab']['mod']. If a modul exist in modul dir but not in
 25:  * $cfg['tab']['mod'] this class will insert the modul in the table.
 26:  *
 27:  * @package    Core
 28:  * @subpackage Backend
 29:  */
 30: class cModuleSynchronizer extends cModuleHandler {
 31: 
 32:     /**
 33:      * The last id of the module that had changed or had added.
 34:      *
 35:      * @var int
 36:      */
 37:     private $_lastIdMod = 0;
 38: 
 39:     /**
 40:      * This method insert a new modul in $cfg['tab']['mod'] table, if
 41:      * the name of modul dont exist
 42:      *
 43:      * @param string $dir
 44:      * @param string $oldModulName
 45:      * @param string $newModulName
 46:      */
 47:     private function _syncModule($dir, $oldModulName, $newModulName) {
 48:         global $client;
 49:         // if modul dont exist in the $cfg['tab']['mod'] table.
 50:         if ($this->_isExistInTable($oldModulName, $client) == false) {
 51:             // add new Module in db-tablle
 52:             $this->_addModul($newModulName, $client);
 53:             cRegistry::appendLastInfoMessage(sprintf(i18n('Module %s successfully synchronized'), $newModulName));
 54:         } else {
 55:             // update the name of the module
 56:             if ($oldModulName != $newModulName) {
 57:                 $this->_updateModulnameInDb($oldModulName, $newModulName, $client);
 58:             }
 59:         }
 60:     }
 61: 
 62:     /**
 63:      * Rename css, js and input/output file
 64:      *
 65:      * @param string $dir
 66:      * @param string $oldModulName
 67:      * @param string $newModulName
 68:      */
 69:     private function _renameFiles($dir, $oldModulName, $newModulName) {
 70:         if (cFileHandler::exists($dir . $newModulName . '/' . $this->_directories['php'] . $oldModulName . '_input.php') == true) {
 71:             rename($dir . $newModulName . '/' . $this->_directories['php'] . $oldModulName . '_input.php', $dir . $newModulName . '/' . $this->_directories['php'] . $newModulName . '_input.php');
 72:         }
 73: 
 74:         if (cFileHandler::exists($dir . $newModulName . '/' . $this->_directories['php'] . $oldModulName . '_output.php') == true) {
 75:             rename($dir . $newModulName . '/' . $this->_directories['php'] . $oldModulName . '_output.php', $dir . $newModulName . '/' . $this->_directories['php'] . $newModulName . '_output.php');
 76:         }
 77: 
 78:         if (cFileHandler::exists($dir . $newModulName . '/' . $this->_directories['css'] . $oldModulName . '.css') == true) {
 79:             rename($dir . $newModulName . '/' . $this->_directories['css'] . $oldModulName . '.css', $dir . $newModulName . '/' . $this->_directories['css'] . $newModulName . '.css');
 80:         }
 81: 
 82:         if (cFileHandler::exists($dir . $newModulName . '/' . $this->_directories['js'] . $oldModulName . '.js') == true) {
 83:             rename($dir . $newModulName . '/' . $this->_directories['js'] . $oldModulName . '.js', $dir . $newModulName . '/' . $this->_directories['js'] . $newModulName . '.js');
 84:         }
 85:     }
 86: 
 87:     /**
 88:      * Rename the Modul files and Modul dir
 89:      *
 90:      * @param string $dir path the the moduls
 91:      * @param string $dirNameOld old dir name
 92:      * @param string $dirNameNew new dir name
 93:      * @param int $client idclient
 94:      * @return boolean true if succes (rename file and directories)
 95:      */
 96:     private function _renameFileAndDir($dir, $dirNameOld, $dirNameNew, $client) {
 97:         if (rename($dir . $dirNameOld, $dir . $dirNameNew) == FALSE) {
 98:             return false;
 99:         } else { // change names of the files
100:             $this->_renameFiles($dir, $dirNameOld, $dirNameNew);
101:         }
102:         return true;
103:     }
104: 
105:     /**
106:      * Compare file change timestemp and the timestemp in ['tab']['mod'].
107:      * If file had changed make new code :conGenerateCodeForAllArtsUsingMod
108:      *
109:      * @return int id of last update module
110:      */
111:     public function compareFileAndModuleTimestamp() {
112:         global $cfg, $cfgClient;
113: 
114:         $synchLock = 0;
115: 
116:         $sql = sprintf('SELECT UNIX_TIMESTAMP(mod1.lastmodified) AS lastmodified,mod1.idclient,description,type, mod1.name, mod1.alias, mod1.idmod FROM %s AS mod1 WHERE mod1.idclient = %s', $this->_cfg['tab']['mod'], $this->_client);
117:         $notification = new cGuiNotification();
118: 
119:         $db = cRegistry::getDb();
120:         $db->query($sql);
121:         $retIdMod = 0;
122: 
123:         while ($db->nextRecord()) {
124:             $showMessage = false;
125: 
126:             $modulePath = $cfgClient[$db->f('idclient')]['module']['path'] . $db->f('alias') . '/';
127:             $modulePHP = $modulePath . $this->_directories['php'] . $db->f('alias');
128: 
129:             $lastmodified = $db->f('lastmodified');
130: 
131:             $lastmodInput = $lastmodOutput = 0;
132: 
133:             if (cFileHandler::exists($modulePHP . '_input.php')) {
134:                 $lastmodInput = filemtime($modulePHP . '_input.php');
135:             }
136: 
137:             if (cFileHandler::exists($modulePHP . '_output.php')) {
138:                 $lastmodOutput = filemtime($modulePHP . '_output.php');
139:             }
140: 
141:             if (cFileHandler::exists($modulePath . "info.xml")) {
142:                 $lastModInfo = filemtime($modulePath . "info.xml");
143:                 if ($lastModInfo > $lastmodified) {
144:                     $modInfo = cXmlBase::xmlStringToArray(cFileHandler::read($modulePath . "info.xml"));
145:                     $mod = new cApiModule($db->f("idmod"));
146:                     if ($modInfo["description"] != $mod->get("description")) {
147:                         $mod->set("description", $modInfo["description"]);
148:                         $this->setLastModified($lastModInfo, $db->f('idmod'));
149:                     }
150:                     if ($modInfo["type"] != $mod->get("type")) {
151:                         $mod->set("type", $modInfo["type"]);
152:                         $this->setLastModified($lastModInfo, $db->f('idmod'));
153:                     }
154: 
155:                     if ($modInfo["name"] != $mod->get("name")) {
156:                         $mod->set("name", $modInfo["name"]);
157:                         $this->setLastModified($lastModInfo, $db->f('idmod'));
158:                     }
159: 
160:                     if ($modInfo["alias"] != $mod->get("alias")) {
161:                         $mod->set("alias", $modInfo["alias"]);
162:                         $this->setLastModified($lastModInfo, $db->f('idmod'));
163:                     }
164:                     $mod->store();
165:                     $synchLock = 1;
166:                     $showMessage = true;
167:                 }
168:             }
169: 
170:             $lastmodabsolute = max($lastmodInput, $lastmodOutput);
171:             if ($lastmodified < $lastmodabsolute) {
172:                 // update
173:                 $synchLock = 1;
174:                 $this->setLastModified($lastmodabsolute, $db->f('idmod'));
175:                 conGenerateCodeForAllArtsUsingMod($db->f('idmod'));
176:                 $showMessage = true;
177:             }
178: 
179:             if (($idmod = $this->_synchronizeFilesystemAndDb($db)) != 0) {
180:                 $retIdMod = $idmod;
181:             }
182: 
183:             if ($showMessage) {
184:                 cRegistry::appendLastInfoMessage(sprintf(i18n('Module %s successfully synchronized'), $db->f('name')));
185:             }
186:         }
187: 
188:         if ($synchLock == 0) {
189:             cRegistry::addInfoMessage(i18n('All modules are already synchronized'));
190:         }
191: 
192:         // we need it for the update of moduls on the left site (module/backend)
193:         return $retIdMod;
194:     }
195: 
196:     /**
197:      * If someone delete a moduldir with ftp/ssh.
198:      * We have a modul
199:      * in db but not in directory, if the modul in use make a new modul in
200:      * fileystem but if not
201:      * clear it from filesystem.
202:      *
203:      * @param $db
204:      * @return int id of last update module
205:      */
206:     private function _synchronizeFilesystemAndDb($db) {
207:         $returnIdMod = 0;
208:         $this->initWithDatabaseRow($db);
209:         // modul dont exist in filesystem
210:         if ($this->modulePathExists() == false) {
211:             $modul = new cApiModule($db->f('idmod'));
212:             $returnIdMod = $db->f('idmod');
213:             if ($modul->moduleInUse($db->f('idmod')) == true) {
214:                 // modul in use, make new modul in filesystem
215:                 if ($this->createModule() == false) {
216:                     $notification = new cGuiNotification();
217:                     $notification->displayNotification('error', i18n("Can not create module") . " " . $db->f('name'));
218:                 }
219:             } else {
220:                 // modul not in use, delete it
221:                 $sql = sprintf('DELETE  FROM %s WHERE idmod = %s AND idclient = %s', $this->_cfg['tab']['mod'], $db->f('idmod'), $this->_client);
222:                 $myDb = cRegistry::getDb();
223:                 $myDb->query($sql);
224:             }
225:         }
226:         return $returnIdMod;
227:     }
228: 
229:     /**
230:      * Depending on the client, this method
231:      * will check the modul dir of the client and if found
232:      * a Modul(Dir) that not exist in Db-table this method will
233:      * insert the Modul in Db-table ([tab][mod]).
234:      *
235:      * @return int last id of synchronized module
236:      */
237:     public function synchronize() {
238:         global $cfg, $cfgClient;
239: 
240:         // get the path to the modul dir from the client
241:         $dir = $cfgClient[$this->_client]['module']['path'];
242: 
243:         if (is_dir($dir)) {
244:             if (false !== ($handle = cDirHandler::read($dir))) {
245:                 foreach ($handle as $file) {
246:                     if (false === cFileHandler::fileNameBeginsWithDot($file) && is_dir($dir . $file . '/')) {
247:                         $newFile = cApiStrCleanURLCharacters($file);
248:                         // dir is ok
249:                         if ($newFile == $file) {
250:                             $this->_syncModule($dir, $file, $newFile);
251:                         } else { // dir not ok (with not allowed characters)
252:                             if (is_dir($dir . $newFile)) { // exist the new dir
253:                                 // name?
254:                                 // make new dirname
255:                                 $newDirName = $newFile . substr(md5(time() . rand(0, time())), 0, 4);
256:                         
257:                                 // rename
258:                                 if ($this->_renameFileAndDir($dir, $file, $newDirName, $this->_client) != false) {
259:                                     $this->_syncModule($dir, $file, $newDirName);
260:                                 }
261:                             } else { // $newFile (dir) not exist
262:                                 // rename dir old
263:                                 if ($this->_renameFileAndDir($dir, $file, $newFile, $this->_client) != false) {
264:                                     $this->_syncModule($dir, $file, $newFile);
265:                                 }
266:                             }
267:                         }
268:                     }
269:                 }
270:             }
271:         }
272: 
273:         // last Modul Id that will refresh the windows /modul overview
274:         return $this->_lastIdMod;
275:     }
276: 
277:     /**
278:      * This method look in the db-table $cfg['tab']['mod'] for a modul
279:      * name.
280:      * If the modul name exist it will return true
281:      *
282:      * @param $alias
283:      * @param int $idclient idclient
284:      * @internal param string $name name ot the modul
285:      * @return bool if a modul with the $name exist in the $cfg['tab']['mod'] table
286:      *         return true else false
287:      */
288:     private function _isExistInTable($alias, $idclient) {
289:         $db = cRegistry::getDb();
290: 
291:         // Select depending from idclient all moduls wiht the name $name
292:         $sql = sprintf("SELECT * FROM %s WHERE alias='%s' AND idclient=%s", $this->_cfg['tab']['mod'], $alias, $idclient);
293: 
294:         $db->query($sql);
295: 
296:         // a record is found
297:         if ($db->nextRecord()) {
298:             return true;
299:         } else {
300:             return false;
301:         }
302:     }
303: 
304:     /**
305:      * Update the name of module (if the name not allowes)
306:      *
307:      * @param string $oldName old name
308:      * @param string $newName new module name
309:      * @param int $idclient id of client
310:      */
311:     private function _updateModulnameInDb($oldName, $newName, $idclient) {
312:         $db = cRegistry::getDb();
313: 
314:         // Select depending from idclient all modules wiht the name $name
315:         $sql = sprintf("SELECT * FROM %s WHERE alias='%s' AND idclient=%s", $this->_cfg['tab']['mod'], $oldName, $idclient);
316: 
317:         $db->query($sql);
318: 
319:         // a record is found
320:         if ($db->nextRecord()) {
321:             $sqlUpdateName = sprintf("UPDATE %s SET alias='%s' WHERE idmod=%s", $this->_cfg['tab']['mod'], $newName, $db->f('idmod'));
322:             $db->query($sqlUpdateName);
323:             return;
324:         }
325:     }
326: 
327:     /**
328:      * This method add a new Modul in the table $cfg['tab']['mod'].
329:      *
330:      * @param string $name neme of the new module
331:      * @param int $idclient mandant of the module
332:      */
333:     private function _addModul($name, $idclient) {
334:         // insert new modul in con_mod
335:         $oModColl = new cApiModuleCollection();
336:         $oMod = $oModColl->create($name, $idclient, $name);
337:         if (is_object($oMod)) {
338:             // save the last id from modul
339:             $this->_lastIdMod = $oMod->get('idmod');
340:         }
341:     }
342: 
343:     /**
344:      * Update the con_mod, the field lastmodified
345:      *
346:      * @param int $timestamp timestamp of last modification
347:      * @param int $idmod id of modul
348:      */
349:     public function setLastModified($timestamp, $idmod) {
350:         $oMod = new cApiModule((int) $idmod);
351:         if ($oMod->isLoaded()) {
352:             $oMod->set('lastmodified', date('Y-m-d H:i:s', $timestamp));
353:             $oMod->store();
354:         }
355:     }
356: 
357: }
358: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen