Inheritance: extends BaseObject
Esempio n. 1
0
 /**
  * File send part have fun, much todo here so let`s play a round :P
  */
 private function pageSyncFromShowStep7()
 {
     /* ---------------------------------------------------------------------
      * Init
      */
     if ($this->objStepPool->step == null) {
         $this->objStepPool->step = 1;
     }
     // Set content back to normale mode
     $this->booError = false;
     $this->strError = "";
     $this->objData->setState(SyncCtoEnum::WORK_WORK);
     /* ---------------------------------------------------------------------
      * Run page
      */
     try {
         switch ($this->objStepPool->step) {
             /**
              * Init
              */
             case 1:
                 $this->objData->setState(SyncCtoEnum::WORK_WORK);
                 $this->objData->setDescription($GLOBALS['TL_LANG']['tl_syncCto_sync']['step_1']['description_2']);
                 $this->objData->setTitle($GLOBALS['TL_LANG']['MSC']['step'] . " %s");
                 $this->objStepPool->step++;
                 break;
                 /**
                  * Cleanup
                  */
             /**
              * Cleanup
              */
             case 2:
                 $this->objSyncCtoCommunicationClient->purgeTempFolder();
                 $this->objSyncCtoFiles->purgeTemp();
                 $this->objStepPool->step++;
                 break;
                 /**
                  * Call the final operations hook
                  */
             /**
              * Call the final operations hook
              */
             case 3:
                 $arrResponse = $this->objSyncCtoHelper->executeFinalOperations();
                 $this->objStepPool->step++;
                 break;
             case 4:
                 $this->objSyncCtoCommunicationClient->referrerEnable();
                 $this->objStepPool->step++;
                 break;
             case 5:
                 $this->objSyncCtoCommunicationClient->stopConnection();
                 SyncCtoStats::getInstance()->addEndStat(time());
                 $this->objStepPool->step++;
                 break;
                 /**
                  * Show information
                  */
             /**
              * Show information
              */
             case 6:
                 // Count files
                 if (is_array($this->arrListCompare) && (count($this->arrListCompare['core']) != 0 || count($this->arrListCompare['files']) != 0)) {
                     $intSkippCount = 0;
                     $intSendCount = 0;
                     $intWaitCount = 0;
                     $intDelCount = 0;
                     $intSplitCount = 0;
                     foreach ($this->arrListCompare as $strType => $arrLists) {
                         foreach ($arrLists as $key => $value) {
                             switch ($value["transmission"]) {
                                 case SyncCtoEnum::FILETRANS_SEND:
                                     $intSendCount++;
                                     break;
                                 case SyncCtoEnum::FILETRANS_SKIPPED:
                                     $intSkippCount++;
                                     break;
                                 case SyncCtoEnum::FILETRANS_WAITING:
                                     $intWaitCount++;
                                     break;
                             }
                             if ($value["state"] == SyncCtoEnum::FILESTATE_DELETE || $value["state"] == SyncCtoEnum::FILESTATE_FOLDER_DELETE) {
                                 $intDelCount++;
                             }
                             if ($value["split"] == true) {
                                 $intSplitCount++;
                             }
                         }
                     }
                 }
                 // Hide control div
                 $this->Template->showControl = false;
                 $this->Template->showNextControl = true;
                 // If no files are send show success msg
                 if (!is_array($this->arrListCompare) || count($this->arrListCompare['core']) == 0 && count($this->arrListCompare['files']) == 0) {
                     $this->objData->setHtml("");
                     $this->objData->setState(SyncCtoEnum::WORK_OK);
                     $this->objData->setDescription($GLOBALS['TL_LANG']['tl_syncCto_sync']['step_1']['description_2']);
                     $this->booFinished = true;
                     // Set finished msg
                     // Set success information
                     $arrClientLink = \Database::getInstance()->prepare("SELECT * FROM tl_synccto_clients WHERE id=?")->limit(1)->execute($this->intClientID)->fetchAllAssoc();
                     $strLink = vsprintf('<a href="%s:%s%s" target="_blank" style="text-decoration:underline;">', array($arrClientLink[0]['address'], $arrClientLink[0]['port'], $arrClientLink[0]['path']));
                     $this->objData->nextStep();
                     $this->objData->setTitle($GLOBALS['TL_LANG']['MSC']['complete']);
                     $this->objData->setDescription(vsprintf($GLOBALS['TL_LANG']['tl_syncCto_sync']['complete_client'], array($strLink, "</a>")));
                     $this->objData->setState(SyncCtoEnum::WORK_OK);
                     break;
                 } elseif (is_array($this->arrListCompare) && (count($this->arrListCompare['core']) != 0 || count($this->arrListCompare['files']) != 0)) {
                     $this->objData->setHtml("");
                     $this->objData->setState(SyncCtoEnum::WORK_OK);
                     $this->objData->setDescription(vsprintf($GLOBALS['TL_LANG']['tl_syncCto_sync']["step_3"]['description_2'], array($intSendCount, count($this->arrListCompare['core']) + count($this->arrListCompare['files']))));
                     $this->booFinished = true;
                 }
                 $compare = '';
                 // Check if there are some skipped files
                 if ($intSkippCount != 0) {
                     $compare .= '<br /><p class="tl_help">' . $intSkippCount . $GLOBALS['TL_LANG']['tl_syncCto_sync']["step_5"]['description_3'] . '</p>';
                     $arrSort = array();
                     foreach ($this->arrListCompare as $strType => $arrLists) {
                         foreach ($arrLists as $value) {
                             if ($value["transmission"] != SyncCtoEnum::FILETRANS_SKIPPED) {
                                 continue;
                             }
                             $skipreason = preg_replace("/(RPC Call:.*|\\<br\\>|\\<br\\/\\>)/i", " ", $value["skipreason"]);
                             $arrSort[$skipreason][] = $value;
                         }
                     }
                     $compare .= '<ul class="fileinfo">';
                     foreach ($arrSort as $strMsg => $arrFiles) {
                         $compare .= "<li>";
                         $compare .= '<strong>' . $strMsg . '</strong>';
                         $compare .= "<ul>";
                         foreach ($arrFiles as $arrFile) {
                             $compare .= sprintf('<li title="%s">%s</li>', $arrFile['error'], $arrFile['path']);
                         }
                         $compare .= "</ul>";
                         $compare .= "</li>";
                     }
                     $compare .= "</ul>";
                 }
                 // Write some information about the dbafs.
                 if (is_array($this->arrListCompare) && count($this->arrListCompare['files']) != 0) {
                     $arrDbafsFiles = array();
                     foreach ($this->arrListCompare['files'] as $key => $value) {
                         // Skip files without the dbafs information and no problems with the dbafs.
                         if (!isset($value['dbafs']) || $value['dbafs']['state'] != SyncCtoEnum::DBAFS_CONFLICT) {
                             continue;
                         }
                         // Add entries to the list.
                         $arrDbafsFiles[$value['dbafs']['msg']][] = $value;
                     }
                     $compare .= '<ul class="dbafsinfo">';
                     $compare .= "<li>";
                     if (count($arrDbafsFiles) == 0) {
                         $compare .= $GLOBALS['TL_LANG']['MSC']['dbafs_all_green'];
                     } else {
                         $compare .= $GLOBALS['TL_LANG']['ERR']['dbafs_error'];
                         $compare .= '<ul>';
                         foreach ($arrDbafsFiles as $strMsg => $arrFiles) {
                             $compare .= '<li>';
                             $compare .= sprintf('<p>%s</p>', $strMsg);
                             $compare .= '<ul>';
                             foreach ($arrFiles as $arrFile) {
                                 $compare .= sprintf('<li title="%s">', $arrFile['dbafs']['error']);
                                 $compare .= $arrFile['path'];
                                 $compare .= '</li>';
                             }
                             $compare .= '</ul>';
                             $compare .= '</li>';
                         }
                         $compare .= '</ul>';
                     }
                     $compare .= "</li>";
                     $compare .= "</ul>";
                 }
                 // Show file list only in debug mode
                 if ($GLOBALS['TL_CONFIG']['syncCto_debug_mode'] == true) {
                     if (is_array($this->arrListCompare) && (count($this->arrListCompare['core']) != 0 || count($this->arrListCompare['files']) != 0)) {
                         $compare .= '<br /><p class="tl_help">' . $intSendCount . $GLOBALS['TL_LANG']['tl_syncCto_sync']["step_5"]['description_4'] . '</p>';
                         if ($intSendCount - $intDelCount != 0) {
                             $compare .= '<ul class="fileinfo">';
                             $compare .= "<li>";
                             $compare .= '<strong>' . $GLOBALS['TL_LANG']['tl_syncCto_sync']["step_5"]['description_6'] . '</strong>';
                             $compare .= "<ul>";
                             foreach ($this->arrListCompare as $strType => $arrLists) {
                                 foreach ($arrLists as $key => $value) {
                                     if ($value["transmission"] != SyncCtoEnum::FILETRANS_SEND) {
                                         continue;
                                     }
                                     if ($value["state"] == SyncCtoEnum::FILESTATE_DELETE) {
                                         continue;
                                     }
                                     $compare .= "<li>";
                                     $compare .= mb_check_encoding($value["path"], 'UTF-8') ? $value["path"] : utf8_encode($value["path"]);
                                     $compare .= "</li>";
                                 }
                             }
                             $compare .= "</ul>";
                             $compare .= "</li>";
                             $compare .= "</ul>";
                         }
                         if ($intDelCount != 0) {
                             $compare .= '<ul class="fileinfo">';
                             $compare .= "<li>";
                             $compare .= '<strong>' . $GLOBALS['TL_LANG']['tl_syncCto_sync']["step_5"]['description_7'] . '</strong>';
                             $compare .= "<ul>";
                             $compare .= "<li>";
                             $compare .= '<strong>' . $GLOBALS['TL_LANG']['tl_syncCto_sync']["step_5"]['description_7'] . '</strong>';
                             $compare .= "<ul>";
                             foreach ($this->arrListCompare as $strType => $arrLists) {
                                 foreach ($arrLists as $key => $value) {
                                     if ($value["transmission"] != SyncCtoEnum::FILETRANS_SEND) {
                                         continue;
                                     }
                                     if ($value["state"] != SyncCtoEnum::FILESTATE_DELETE) {
                                         continue;
                                     }
                                     $compare .= "<li>";
                                     $compare .= mb_check_encoding($value["path"], 'UTF-8') ? $value["path"] : utf8_encode($value["path"]);
                                     $compare .= "</li>";
                                 }
                             }
                             $compare .= "</ul>";
                             $compare .= "</li>";
                             $compare .= "<li>";
                             $compare .= '<strong>' . $GLOBALS['TL_LANG']['tl_syncCto_sync']["step_5"]['description_9'] . '</strong>';
                             $compare .= "<ul>";
                             foreach ($this->arrListCompare as $strType => $arrLists) {
                                 foreach ($arrLists as $key => $value) {
                                     if ($value["transmission"] != SyncCtoEnum::FILETRANS_SEND) {
                                         continue;
                                     }
                                     if ($value["state"] != SyncCtoEnum::FILESTATE_FOLDER_DELETE) {
                                         continue;
                                     }
                                     $compare .= "<li>";
                                     $compare .= mb_check_encoding($value["path"], 'UTF-8') ? $value["path"] : utf8_encode($value["path"]);
                                     $compare .= "</li>";
                                 }
                             }
                             $compare .= "</ul>";
                             $compare .= "</li>";
                             $compare .= "</ul>";
                             $compare .= "</li>";
                             $compare .= "</ul>";
                         }
                         // Not send and still waiting
                         if ($intWaitCount != 0) {
                             $compare .= '<br /><p class="tl_help">' . $intWaitCount . $GLOBALS['TL_LANG']['tl_syncCto_sync']["step_5"]['description_5'] . '</p>';
                             $compare .= '<ul class="fileinfo">';
                             $compare .= "<li>";
                             $compare .= '<strong>' . $GLOBALS['TL_LANG']['tl_syncCto_sync']["step_5"]['description_8'] . '</strong>';
                             $compare .= "<ul>";
                             foreach ($this->arrListCompare as $strType => $arrLists) {
                                 foreach ($arrLists as $key => $value) {
                                     if ($value["transmission"] != SyncCtoEnum::FILETRANS_WAITING) {
                                         continue;
                                     }
                                     $compare .= "<li>";
                                     $compare .= mb_check_encoding($value["path"], 'UTF-8') ? $value["path"] : utf8_encode($value["path"]);
                                     $compare .= "</li>";
                                 }
                             }
                             $compare .= "</ul>";
                             $compare .= "</li>";
                             $compare .= "</ul>";
                         }
                     }
                 }
                 $this->objData->setHtml($compare);
                 // Set finished msg
                 $arrClientLink = \Database::getInstance()->prepare("SELECT * FROM tl_synccto_clients WHERE id=?")->limit(1)->execute($this->intClientID)->fetchAllAssoc();
                 $strLink = vsprintf('<a href="%s:%s%s" target="_blank" style="text-decoration:underline;">', array($arrClientLink[0]['address'], $arrClientLink[0]['port'], $arrClientLink[0]['path']));
                 $this->objData->nextStep();
                 $this->objData->setTitle($GLOBALS['TL_LANG']['MSC']['complete']);
                 $this->objData->setDescription(vsprintf($GLOBALS['TL_LANG']['tl_syncCto_sync']['complete_client'], array($strLink, "</a>")));
                 $this->objData->setState(SyncCtoEnum::WORK_OK);
                 break;
         }
     } catch (Exception $exc) {
         $this->objStepPool->step++;
         $this->log(vsprintf("Error on synchronization client ID %s with msg: %s", array(\Input::get("id"), $exc->getMessage())), __CLASS__ . " " . __FUNCTION__, "ERROR");
     }
 }
Esempio n. 2
0
 /**
  * Sets the content of a file object to that in
  * the given source file
  *
  * @param File $file
  * @param string $sourceFile
  */
 public function setFile(File $file, $sourceFile)
 {
     if (!$this->getConnection()) {
         return null;
     }
     ini_set('memory_limit', '64M');
     $node = $this->nodeFromFile($file);
     if (!$node) {
         return;
     }
     $content = new ContentData($node, NamespaceMap::getFullName("cm_content"));
     $mimeType = get_mime_content_type($sourceFile);
     $sourceContent = file_get_contents($sourceFile);
     $content->setContent($sourceContent);
     $content->setMimetype($mimeType);
     $node->cm_content = $content;
     $this->alfresco->save();
 }
Esempio n. 3
0
 protected function pageFileRestorePage()
 {
     // Init | Set Step to 1
     if ($this->intStep == 0) {
         // Init content
         $this->booError = false;
         $this->booAbort = false;
         $this->booFinished = false;
         $this->strError = "";
         $this->booRefresh = true;
         $this->strUrl = "contao/main.php?do=syncCto_backups&amp;table=tl_syncCto_restore_file&amp;act=start";
         $this->strGoBack = \Environment::get('base') . "contao/main.php?do=syncCto_backups&table=tl_syncCto_restore_file";
         $this->strHeadline = $GLOBALS['TL_LANG']['tl_syncCto_restore_file']['edit'];
         $this->strInformation = "";
         $this->intStep = 1;
         $this->floStart = microtime(true);
         $this->objData = new ContentData(array(), $this->intStep);
         // Reset some Sessions
         $this->resetStepPool();
     }
     // Load step pool
     $this->loadStepPool();
     // Set content back to normale mode
     $this->booRefresh = true;
     $this->objData->setStep(1);
     $this->objData->setState(SyncCtoEnum::WORK_WORK);
     $this->objData->setHtml("");
     try {
         switch ($this->intStep) {
             case 1:
                 $this->objData->setTitle($GLOBALS['TL_LANG']['MSC']['step'] . " %s");
                 $this->objData->setDescription($GLOBALS['TL_LANG']['tl_syncCto_restore_file']['step1']);
                 $this->objData->setState(SyncCtoEnum::WORK_WORK);
                 $this->intStep++;
                 break;
             case 2:
                 try {
                     $mixResponse = $this->objSyncCtoFiles->runRestore($this->arrBackupSettings['syncCto_restoreFile']);
                     if ($mixResponse !== true) {
                         $strHTML = $GLOBALS['TL_LANG']['ERR']['cant_extract_file'];
                         $strHTML .= "<br />";
                         $strHTML .= "<ul>";
                         foreach ($mixResponse as $value) {
                             $strHTML .= "<li>" . $value . "</li>";
                         }
                         $strHTML .= "</ul>";
                         $this->booError = true;
                         $this->strError = $strHTML;
                         $this->objData->setStep(1);
                         $this->objData->setDescription($GLOBALS['TL_LANG']['ERR']['cant_extract_file']);
                         break;
                     }
                     $this->intStep++;
                     break;
                 } catch (Exception $exc) {
                     $this->booError = true;
                     $this->strError = $exc->getMessage();
                     $this->objData->setStep(1);
                     $this->objData->setState(SyncCtoEnum::WORK_ERROR);
                     break;
                 }
             case 3:
                 $objDate = new Date();
                 $this->booFinished = true;
                 $this->booRefresh = false;
                 $this->objData->setStep(1);
                 $this->objData->setState(SyncCtoEnum::WORK_OK);
                 $this->objData->setStep(2);
                 $this->objData->setTitle($GLOBALS['TL_LANG']['MSC']['complete']);
                 $this->objData->setDescription(vsprintf($GLOBALS['TL_LANG']['tl_syncCto_restore_file']['complete'], array($this->arrBackupSettings['backup_file'], $objDate->time, $objDate->date)));
                 $this->objData->setState(SyncCtoEnum::WORK_OK);
                 break;
         }
     } catch (Exception $exc) {
         $objErrTemplate = new BackendTemplate('be_syncCto_error');
         $objErrTemplate->strErrorMsg = $exc->getMessage();
         $this->booRefresh = false;
         $this->objData->setState(SyncCtoEnum::WORK_ERROR);
         $this->objData->setHtml($objErrTemplate->parse());
     }
 }
 function __construct()
 {
     parent::__construct('help');
 }