/** * Get current instnce * * @return SyncCtoUpdater */ public static function getInstance() { if (self::$instance == null) { self::$instance = new SyncCtoUpdater(); } return self::$instance; }
/** * Start the connection and save some parameter to session */ private function pageSyncShowStep1() { // Init if ($this->objStepPool->step == null) { $this->objStepPool->step = 1; } // Set content back to normale mode $this->strError = ""; $this->booError = false; $this->objData->setState(SyncCtoEnum::WORK_WORK); /* --------------------------------------------------------------------- * Run page */ try { switch ($this->objStepPool->step) { /** * Show step */ case 1: $this->objData->setTitle($GLOBALS['TL_LANG']['MSC']['step'] . " %s"); $this->objData->setDescription($GLOBALS['TL_LANG']['tl_syncCto_sync']["step_1"]['description_1']); $this->objData->setState(SyncCtoEnum::WORK_WORK); $this->objStepPool->step++; break; /** * Start connection */ /** * Start connection */ case 2: $this->objSyncCtoCommunicationClient->startConnection(); $this->objStepPool->step++; break; /** * Referer check deactivate */ /** * Referer check deactivate */ case 3: if (!$this->objSyncCtoCommunicationClient->referrerDisable()) { $this->objData->setState(SyncCtoEnum::WORK_ERROR); $this->booError = true; $this->strError = $GLOBALS['TL_LANG']['ERR']['referer']; break; } $this->objStepPool->step++; break; /** * Check version */ /** * Check version */ case 4: // Check if the composer is enabled if enabled skip the auto update. if (!in_array('!composer', \Config::getInstance()->getActiveModules())) { // Check syncCto $strVersion = $this->objSyncCtoCommunicationClient->getVersionSyncCto(); $this->arrClientInformation["version_SyncCto"] = $strVersion; if (version_compare($strVersion, $GLOBALS['SYC_VERSION'], "=")) { $this->objStepPool->autoUpdate = false; } else { $this->objStepPool->autoUpdate = true; } } else { $this->objStepPool->autoUpdate = false; } // Check Contao $strVersion = $this->objSyncCtoCommunicationClient->getVersionContao(); $this->arrClientInformation["version_Contao"] = $strVersion; $strVersion = trimsplit(".", $strVersion); $strVersion = $strVersion[0]; $strCurrentVersion = trimsplit(".", VERSION); $strCurrentVersion = $strCurrentVersion[0]; if ($strVersion != $strCurrentVersion) { $this->log(vsprintf("Not the same version from contao on synchronization client ID %s. Serverversion: %s. Clientversion: %s", array(\Input::get("id"), $GLOBALS['SYC_VERSION'], $strVersion)), __CLASS__ . " " . __FUNCTION__, "GENERAL"); $this->objData->setState(SyncCtoEnum::WORK_ERROR); $this->booError = true; $this->strError = vsprintf($GLOBALS['TL_LANG']['ERR']['version'], array("Contao", $strCurrentVersion, $strVersion)); break; } $this->objData->setDescription($GLOBALS['TL_LANG']['tl_syncCto_sync']["step_1"]['description_2']); $this->objStepPool->step++; break; /** * Clear client and server temp folder */ /** * Clear client and server temp folder */ case 5: $this->objSyncCtoCommunicationClient->purgeTempFolder(); $this->objSyncCtoFiles->purgeTemp(); // Current step is okay. $this->objData->setDescription($GLOBALS['TL_LANG']['tl_syncCto_sync']["step_1"]['description_1']); $this->objStepPool->step++; break; /** * Load parameter from client */ /** * Load parameter from client */ case 6: // Load the folder settings. Temp Folder | Backup Folder | Log Folder etc. $arrFolders = $this->objSyncCtoCommunicationClient->getPathList(); $this->arrClientInformation["folders"] = $arrFolders; // Get parameter for upload and co $arrClientParameter = $this->objSyncCtoCommunicationClient->getClientParameter(); $this->arrClientInformation["upload_Parameter"] = $arrClientParameter; // Check if everything is okay if ($arrClientParameter['file_uploads'] != 1) { $this->objData->setState(SyncCtoEnum::WORK_ERROR); $this->booError = true; $this->strError = $GLOBALS['TL_LANG']['ERR']['upload_ini']; break; } $intClientUploadLimit = static::parseSize($arrClientParameter['upload_max_filesize']); $intClientMemoryLimit = static::parseSize($arrClientParameter['memory_limit']); $intClientPostLimit = static::parseSize($arrClientParameter['post_max_size']); $intLocalMemoryLimit = static::parseSize(ini_get('memory_limit')); // Check if memory limit on server and client is enough for upload $intLimit = min($intClientUploadLimit, $intClientMemoryLimit, $intClientPostLimit, $intLocalMemoryLimit); // Limit if ($intLimit > 1073741824) { // 1GB $intPercent = 10; } else { if ($intLimit > 524288000) { // 500MB $intPercent = 10; } else { if ($intLimit > 209715200) { // 200MB $intPercent = 10; } else { $intPercent = 80; } } } $intLimit = $intLimit / 100 * $intPercent; $this->arrClientInformation["upload_sizeLimit"] = $intLimit; $this->arrClientInformation["upload_sizePercent"] = $intPercent; if ($this->objStepPool->autoUpdate == false) { $this->objStepPool->step = 11; } else { $this->objData->setDescription($GLOBALS['TL_LANG']['tl_syncCto_sync']['step_1']['description_3']); $this->objStepPool->step++; } break; /** * Auto Updater */ /** * Auto Updater */ case 7: $objSyncCtoUpdater = SyncCtoUpdater::getInstance(); $strZipPath = $this->objSyncCtoHelper->standardizePath($GLOBALS['SYC_PATH']['tmp'], "autoupdater", "autoupdate_" . time() . ".zip"); new Folder(dirname($strZipPath)); $objSyncCtoUpdater->buildUpdateZip($strZipPath); $this->objStepPool->AutoUpdateZip = $strZipPath; $this->objStepPool->step++; break; // Send files // Send files case 8: $arrFiles = array("system/modules/syncCtoUpdater/SyncCtoAutoUpdater.php", "system/modules/syncCtoUpdater/config/config.php", "system/modules/syncCtoUpdater/config/.htaccess", $this->objStepPool->AutoUpdateZip); foreach ($arrFiles as $value) { $this->objSyncCtoCommunicationClient->sendFile(dirname($value), basename($value), "", SyncCtoEnum::UPLOAD_SYNC_TEMP); } $this->objStepPool->step++; break; // Import files // Import files case 9: $arrFiles = array("system/modules/syncCtoUpdater/SyncCtoAutoUpdater.php", "system/modules/syncCtoUpdater/config/config.php", "system/modules/syncCtoUpdater/config/.htaccess", $this->objStepPool->AutoUpdateZip); $arrImport = array(); foreach ($arrFiles as $value) { $strChecksum = md5(TL_ROOT . "/" . $value); $arrImport[$strChecksum] = array("path" => $value, "checksum" => $strChecksum, "size" => 0, "state" => SyncCtoEnum::FILESTATE_FILE, "transmission" => SyncCtoEnum::FILETRANS_WAITING); } $this->objSyncCtoCommunicationClient->runFileImport($arrImport, false); $this->objStepPool->step++; break; // Start update // Start update case 10: $this->objSyncCtoCommunicationClient->startAutoUpdater($this->objStepPool->AutoUpdateZip); $this->objStepPool->step++; break; // Check pathconfig for contao 2.11.10 =< // Check pathconfig for contao 2.11.10 =< case 11: $this->objSyncCtoCommunicationClient->createPathconfig(); $this->objStepPool->step++; break; case 12: $this->objData->setDescription($GLOBALS['TL_LANG']['tl_syncCto_sync']["step_1"]['description_1']); $this->objData->setState(SyncCtoEnum::WORK_OK); $this->intStep++; break; } } catch (Exception $exc) { $this->log(vsprintf("Error on synchronization client ID %s with msg: %s", array(\Input::get("id"), $exc->getMessage())), __CLASS__ . " " . __FUNCTION__, "ERROR"); $this->booError = true; $this->strError = $exc->getMessage(); $this->objData->setState(SyncCtoEnum::WORK_ERROR); } }