コード例 #1
0
ファイル: SyncCtoStats.php プロジェクト: menatwork/synccto
 /**
  * Get current instance
  * 
  * @return SyncCtoStats
  */
 public static function getInstance()
 {
     if (is_null(self::$objInstance)) {
         self::$objInstance = new self();
     }
     return self::$objInstance;
 }
コード例 #2
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");
     }
 }