Exemplo n.º 1
0
 /**
  * Request-Handler
  * @return boolean
  */
 public function request()
 {
     if ($this->getRequestVar('step')) {
         $this->forceStep = (int) $this->getRequestVar('step');
     }
     \fpcm\classes\baseconfig::enableAsyncCronjobs(false);
     return parent::request();
 }
Exemplo n.º 2
0
 /**
  * Kopiert Inhalt von Paket von Quelle nach Ziel
  * @return boolean
  */
 public function copy()
 {
     if (!file_exists($this->tempListFile)) {
         \fpcm\classes\baseconfig::enableAsyncCronjobs(true);
         return false;
     }
     $this->loadPackageFileListFromTemp();
     if (!count($this->files)) {
         \fpcm\classes\baseconfig::enableAsyncCronjobs(true);
         return false;
     }
     $res = true;
     foreach ($this->files as $zipFile) {
         $source = $this->extractPath . $zipFile;
         $dest = dirname(\fpcm\classes\baseconfig::$baseDir) . $this->copyDestination . $zipFile;
         $dest = is_dir($source) ? dirname($dest) . '/' . basename($dest) : $dest;
         $dest = $this->replaceFanpressDirString($dest);
         if (substr($dest, -8) === 'fanpress') {
             continue;
         }
         if (is_dir($source)) {
             if (!file_exists($dest) && !mkdir($dest, 0777)) {
                 if (!is_array($res)) {
                     $res = array();
                 }
                 $res[] = $dest;
             }
             continue;
         }
         if (file_exists($dest)) {
             if (sha1_file($source) == sha1_file($dest)) {
                 continue;
             }
             $backFile = $dest . '.back';
             if (file_exists($backFile)) {
                 unlink($backFile);
             }
             rename($dest, $backFile);
         }
         if (!copy($source, $dest)) {
             if (!is_array($res)) {
                 $res = array();
             }
             $res[] = $dest;
         }
     }
     if (is_array($res)) {
         $this->copyErrorPaths = $res;
     }
     return is_array($res) ? self::FPCMPACKAGE_FILESCOPY_ERROR : $res;
 }
Exemplo n.º 3
0
 /**
  * Kopiert Inhalt von Paket von Quelle nach Ziel
  * @return boolean
  */
 public function copy()
 {
     if (!file_exists($this->tempListFile)) {
         \fpcm\classes\baseconfig::enableAsyncCronjobs(true);
         return false;
     }
     $this->loadPackageFileListFromTemp();
     if (!count($this->files)) {
         \fpcm\classes\baseconfig::enableAsyncCronjobs(true);
         return false;
     }
     $vendorFolder = \fpcm\classes\baseconfig::$baseDir . $this->copyDestination . dirname($this->key);
     if (!is_dir($vendorFolder) && !mkdir($vendorFolder)) {
         trigger_error('Unable to create module vendor folder ' . \fpcm\model\files\ops::removeBaseDir($vendorFolder, true));
         \fpcm\classes\baseconfig::enableAsyncCronjobs(true);
         return false;
     }
     $res = true;
     foreach ($this->files as $zipFile) {
         $source = $this->extractPath . $zipFile;
         $dest = \fpcm\classes\baseconfig::$baseDir . $this->copyDestination . str_replace(basename($this->key) . '/', $this->key . '/', $zipFile);
         $dest = $this->replaceFanpressDirString($dest);
         if (is_dir($source)) {
             if (!file_exists($dest) && !mkdir($dest, 0777)) {
                 if (!is_array($res)) {
                     $res = array();
                 }
                 $res[] = $dest;
             }
             continue;
         }
         if (file_exists($dest)) {
             if (sha1_file($source) == sha1_file($dest)) {
                 continue;
             }
             $backFile = $dest . '.back';
             if (file_exists($backFile)) {
                 unlink($backFile);
             }
             rename($dest, $backFile);
         }
         if (!copy($source, $dest)) {
             if (!is_array($res)) {
                 $res = array();
             }
             $res[] = $dest;
         }
     }
     return is_array($res) ? self::FPCMPACKAGE_FILESCOPY_ERROR : $res;
 }
Exemplo n.º 4
0
 /**
  * Request-Handler
  * @return bool
  */
 public function request()
 {
     if ($this->getRequestVar('step')) {
         $this->forceStep = (int) $this->getRequestVar('step');
     }
     if ($this->getRequestVar('file')) {
         $tmpFile = new \fpcm\model\files\tempfile('forceUpdateFile', $this->getRequestVar('file'));
         $tmpFile->save();
     }
     if (!$this->forceStep) {
         \fpcm\classes\baseconfig::enableAsyncCronjobs(false);
     }
     return parent::request();
 }
Exemplo n.º 5
0
 /**
  * Controller-Processing
  */
 public function process()
 {
     if (!parent::process()) {
         return false;
     }
     if ($this->canConnect) {
         $keyData = \fpcm\model\packages\package::explodeModuleFileName($this->key);
         $pkg = new \fpcm\model\packages\module('module', $keyData[0], $keyData[1]);
     }
     if (!isset($keyData[0]) || !isset($keyData[1])) {
         $this->returnCode = $this->step . '_0';
         $this->getResponse();
     }
     $this->returnData['current'] = $this->step;
     switch ($this->step) {
         case 1:
             $res = $pkg->download();
             $from = $pkg->getRemoteFile();
             if ($res === true) {
                 \fpcm\classes\logs::syslogWrite('Downloaded module package successfully from ' . $from);
                 $this->returnData['nextstep'] = 2;
             } else {
                 \fpcm\classes\logs::syslogWrite('Error while downloading module package from' . $from);
                 $this->returnData['nextstep'] = 5;
             }
             break;
         case 2:
             $res = $pkg->extract();
             $from = \fpcm\model\files\ops::removeBaseDir($pkg->getLocalFile());
             if ($res === true) {
                 \fpcm\classes\logs::syslogWrite('Extracted module package successfully from ' . $from);
                 $this->returnData['nextstep'] = 3;
             } else {
                 \fpcm\classes\logs::syslogWrite('Error while extracting module package from ' . $from);
                 $this->returnData['nextstep'] = 5;
             }
             break;
         case 3:
             $res = $pkg->copy();
             $dest = \fpcm\model\files\ops::removeBaseDir(\fpcm\classes\baseconfig::$baseDir) . $pkg->getCopyDestination() . $pkg->getKey();
             $from = \fpcm\model\files\ops::removeBaseDir($pkg->getExtractPath() . basename($pkg->getKey()));
             if ($res === true) {
                 \fpcm\classes\logs::syslogWrite('Moved module package content successfully from ' . $from . ' to ' . $dest);
                 $this->returnData['nextstep'] = 4;
             } else {
                 \fpcm\classes\logs::syslogWrite('Error while moving module package content from ' . $from . ' to ' . $dest);
                 \fpcm\classes\logs::syslogWrite(implode('<br>', $pkg->getCopyErrorPaths()));
                 $this->returnData['nextstep'] = 5;
             }
             break;
         case 4:
             $moduleClass = \fpcm\model\abstracts\module::getModuleClassName($keyData[0]);
             $res = class_exists($moduleClass);
             $moduleClassPath = \fpcm\classes\baseconfig::$moduleDir . $keyData[0] . '/' . str_replace(array('\\', '/'), '', $keyData[0]) . '.php';
             if (!file_exists($moduleClassPath)) {
                 $res = false;
                 trigger_error('Module class ' . $moduleClass . ' not found in "' . $moduleClassPath . '"!');
                 $this->returnData['nextstep'] = 5;
                 break;
             }
             if ($res) {
                 $modObj = new $moduleClass($keyData[0], '', $keyData[1]);
                 if (!is_a($modObj, '\\fpcm\\model\\abstracts\\module')) {
                     $res = false;
                     trigger_error('Module class ' . $moduleClass . ' must be an instance of "\\fpcm\\model\\abstracts\\module"!');
                     break;
                 }
                 $res = $modObj->runInstall();
             }
             $this->returnData['nextstep'] = 5;
             if ($res === true) {
                 \fpcm\classes\logs::syslogWrite('Run final module install steps successfully for ' . $pkg->getKey());
             } else {
                 \fpcm\classes\logs::syslogWrite('Error while running final module install steps for ' . $pkg->getKey());
             }
             break;
         case 5:
             if ($this->canConnect) {
                 $pkg->loadPackageFileListFromTemp();
                 \fpcm\classes\logs::pkglogWrite($pkg->getKey() . ' ' . $pkg->getVersion(), $pkg->getFiles());
                 $pkg->cleanup();
             }
             \fpcm\classes\baseconfig::enableAsyncCronjobs(true);
             $this->cache->cleanup();
             $res = true;
             break;
         default:
             $res = false;
             break;
     }
     $this->returnCode = $this->step . '_' . (int) $res;
     $this->getResponse();
 }
Exemplo n.º 6
0
 /**
  * Controller-Processing
  */
 public function process()
 {
     if (!parent::process()) {
         return false;
     }
     $this->canConnect = \fpcm\classes\baseconfig::canConnect();
     if ($this->canConnect) {
         $versionDataFile = new \fpcm\model\files\tempfile('newversion');
         if ($versionDataFile->exists() && $versionDataFile->getContent()) {
             $remoteData = json_decode($versionDataFile->getContent(), true);
         } else {
             $updater = new \fpcm\model\updater\system();
             $updater->checkUpdates();
             $remoteData = $updater->getRemoteData();
             $versionDataFile->setContent(json_encode($remoteData));
             $versionDataFile->save();
         }
         $fileInfo = pathinfo($remoteData['filepath'], PATHINFO_FILENAME);
         $tmpFile = new \fpcm\model\files\tempfile('forceUpdateFile');
         if ($tmpFile->exists()) {
             $fileInfo = $tmpFile->getContent();
         }
         $signature = isset($remoteData['signature']) ? $remoteData['signature'] : '';
         $pkg = new \fpcm\model\packages\update('update', $fileInfo, '', $signature);
     }
     $this->returnData['current'] = $this->step;
     switch ($this->step) {
         case 1:
             $res = $pkg->download();
             if ($res === \fpcm\model\packages\package::FPCMPACKAGE_REMOTEFILE_ERROR) {
                 $versionDataFile->delete();
             }
             if ($res === true) {
                 \fpcm\classes\logs::syslogWrite('Downloaded update package successfully from ' . $pkg->getRemoteFile());
                 $this->returnData['nextstep'] = 2;
             } else {
                 \fpcm\classes\logs::syslogWrite('Error while downloading update package from ' . $pkg->getRemoteFile());
                 $this->returnData['nextstep'] = 5;
             }
             break;
         case 2:
             $res = $pkg->extract();
             $from = \fpcm\model\files\ops::removeBaseDir($pkg->getLocalFile());
             if ($res === true) {
                 \fpcm\classes\logs::syslogWrite('Extracted update package successfully from ' . $from);
                 $this->returnData['nextstep'] = 3;
             } else {
                 \fpcm\classes\logs::syslogWrite('Error while extracting update package from ' . $from);
                 $this->returnData['nextstep'] = 5;
             }
             break;
         case 3:
             $res = $pkg->copy();
             $dest = \fpcm\model\files\ops::removeBaseDir(\fpcm\classes\baseconfig::$baseDir);
             $from = \fpcm\model\files\ops::removeBaseDir($pkg->getExtractPath());
             if ($res === true) {
                 \fpcm\classes\logs::syslogWrite('Moved update package content successfully from ' . $from . ' to ' . $dest);
                 $this->returnData['nextstep'] = 4;
             } else {
                 \fpcm\classes\logs::syslogWrite('Error while moving update package content from ' . $from . ' to ' . $dest);
                 \fpcm\classes\logs::syslogWrite(implode('<br>', $pkg->getCopyErrorPaths()));
                 $this->returnData['nextstep'] = 5;
             }
             break;
         case 4:
             $finalizer = new \fpcm\model\updater\finalizer();
             $res = $finalizer->runUpdate();
             $this->returnData['nextstep'] = $this->forceStep ? 6 : 5;
             if ($res === true) {
                 \fpcm\classes\logs::syslogWrite('Run final update steps successfully!');
             } else {
                 \fpcm\classes\logs::syslogWrite('Error while running final update steps!');
             }
             break;
         case 5:
             if ($this->canConnect) {
                 $pkg->loadPackageFileListFromTemp();
                 \fpcm\classes\logs::pkglogWrite($pkg->getKey() . ' ' . $pkg->getVersion(), $pkg->getFiles());
                 $pkg->cleanup();
             }
             \fpcm\classes\baseconfig::enableAsyncCronjobs(true);
             $this->cache->cleanup();
             $res = true;
             $this->returnData['nextstep'] = 6;
             break;
         case 6:
             $this->returnData['newver'] = $this->config->system_version;
             $res = true;
             if ($versionDataFile->exists()) {
                 $versionDataFile->delete();
             }
             break;
         default:
             $res = false;
             break;
     }
     $this->returnCode = $this->step . '_' . (int) $res;
     $this->getResponse();
 }