예제 #1
0
 /**
  * @param string $sSource
  * @param string $sDestination
  */
 public static function CopyDir($sSource, $sDestination)
 {
     if (\is_dir($sSource)) {
         if (!\is_dir($sDestination)) {
             \mkdir($sDestination);
         }
         $oDirectory = \dir($sSource);
         if ($oDirectory) {
             while (false !== ($sRead = $oDirectory->read())) {
                 if ('.' === $sRead || '..' === $sRead) {
                     continue;
                 }
                 $sPathDir = $sSource . '/' . $sRead;
                 if (\is_dir($sPathDir)) {
                     \MailSo\Base\Utils::CopyDir($sPathDir, $sDestination . '/' . $sRead);
                     continue;
                 }
                 \copy($sPathDir, $sDestination . '/' . $sRead);
             }
             $oDirectory->close();
         }
     }
 }
예제 #2
0
 /**
  * @return array
  */
 public function DoAdminUpdateCoreData()
 {
     $this->IsAdminLoggined();
     $bReal = false;
     $sNewVersion = '';
     $bRainLoopUpdatable = $this->rainLoopUpdatable();
     $bRainLoopAccess = $this->rainLoopCoreAccess();
     $aData = array();
     if ($bRainLoopUpdatable && $bRainLoopAccess) {
         $aData = $this->getCoreData($bReal);
     }
     $bResult = false;
     if ($bReal && !empty($aData['file'])) {
         $sTmp = $this->downloadRemotePackageByUrl($aData['file']);
         if (!empty($sTmp)) {
             include_once APP_VERSION_ROOT_PATH . 'app/libraries/pclzip/pclzip.lib.php';
             $oArchive = new \PclZip($sTmp);
             $sTmpFolder = APP_PRIVATE_DATA . \md5($sTmp);
             \mkdir($sTmpFolder);
             if (\is_dir($sTmpFolder)) {
                 $bResult = 0 !== $oArchive->extract(PCLZIP_OPT_PATH, $sTmpFolder);
                 if (!$bResult) {
                     $this->Logger()->Write('Cannot extract package files: ' . $oArchive->errorInfo(), \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
                 }
                 if ($bResult && \file_exists($sTmpFolder . '/index.php') && \is_writable(APP_INDEX_ROOT_PATH . 'rainloop/') && \is_writable(APP_INDEX_ROOT_PATH . 'index.php') && \is_dir($sTmpFolder . '/rainloop/')) {
                     $aMatch = array();
                     $sIndexFile = \file_get_contents($sTmpFolder . '/index.php');
                     if (\preg_match('/\'APP_VERSION\', \'([^\']+)\'/', $sIndexFile, $aMatch) && !empty($aMatch[1])) {
                         $sNewVersion = \trim($aMatch[1]);
                     }
                     if (empty($sNewVersion)) {
                         $this->Logger()->Write('Unknown version', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
                     } else {
                         if (!\is_dir(APP_INDEX_ROOT_PATH . 'rainloop/v/' . $sNewVersion)) {
                             \MailSo\Base\Utils::CopyDir($sTmpFolder . '/rainloop/', APP_INDEX_ROOT_PATH . 'rainloop/');
                             if (\is_dir(APP_INDEX_ROOT_PATH . 'rainloop/v/' . $sNewVersion) && \is_file(APP_INDEX_ROOT_PATH . 'rainloop/v/' . $sNewVersion . '/index.php')) {
                                 $bResult = \copy($sTmpFolder . '/index.php', APP_INDEX_ROOT_PATH . 'index.php');
                                 if ($bResult) {
                                     if (\MailSo\Base\Utils::FunctionExistsAndEnabled('opcache_invalidate')) {
                                         @\opcache_invalidate(APP_INDEX_ROOT_PATH . 'index.php', true);
                                     }
                                     if (\MailSo\Base\Utils::FunctionExistsAndEnabled('apc_delete_file')) {
                                         @\apc_delete_file(APP_INDEX_ROOT_PATH . 'index.php');
                                     }
                                 }
                             } else {
                                 $this->Logger()->Write('Cannot copy new package files', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
                                 $this->Logger()->Write($sTmpFolder . '/rainloop/ -> ' . APP_INDEX_ROOT_PATH . 'rainloop/', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
                             }
                         } else {
                             if (!empty($sNewVersion)) {
                                 $this->Logger()->Write('"' . $sNewVersion . '" version already installed', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
                             }
                         }
                     }
                 } else {
                     if ($bResult) {
                         $this->Logger()->Write('Cannot validate package files', \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
                     }
                 }
                 \MailSo\Base\Utils::RecRmDir($sTmpFolder);
             } else {
                 $this->Logger()->Write('Cannot create tmp folder: ' . $sTmpFolder, \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER');
             }
             @\unlink($sTmp);
         }
     }
     return $this->DefaultResponse(__FUNCTION__, $bResult);
 }