Beispiel #1
0
}
if ($filename) {
    $content .= $cms_language->getMessage(MESSAGE_PAGE_TREAT_FILE) . ' : ' . $filename . '<br /><br />';
} elseif ($cms_action == 'errorsCorrected') {
    $content .= $cms_language->getMessage(MESSAGE_PAGE_RESUME_PATCH) . ' :<br /><br />';
}
if ($filename || $cms_action == 'errorsCorrected') {
    // +----------------------------------------------------------------------+
    // | PATCH FILE TREATMENT                                                 |
    // +----------------------------------------------------------------------+
    $send = '';
    //if it's a patch resume, no need to re-decompress the file
    if ($cms_action != 'errorsCorrected') {
        //patch uncompress
        report('Uncompressing patch in progress...');
        $archive = new CMS_gzip_file($_SERVER['DOCUMENT_ROOT'] . $filename);
        if (!$archive->hasError()) {
            $archive->set_options(array('basedir' => PATH_TMP_FS . "/", 'overwrite' => 1, 'level' => 1, 'dontUseFilePerms' => 1, 'forceWriting' => 1));
            if (is_dir(PATH_TMP_FS)) {
                if (method_exists($archive, 'extract_files') && $archive->extract_files()) {
                    verbose('-> Extract ' . $filename . ' to ' . PATH_TMP_FS);
                }
            } else {
                report('Error : Extraction directory does not exist', true);
            }
        } else {
            report('Error : Unable to extract archive wanted ' . $filename . '. It is not a valid format...', true);
        }
        if (!$archive->hasError()) {
            verbose('-> Extraction successfull');
        } else {
Beispiel #2
0
 /**
  * Export module datas
  * 
  * @param string $format, the export format in : php (default), xml, patch
  * @return mixed : the exported datas
  */
 function export($format = 'php')
 {
     $aExport = array();
     if ($this->_hasExport) {
         //force default language loading to overwrite user language
         global $cms_language;
         $oModule = CMS_modulesCatalog::getByCodename($this->_module);
         if (!$oModule->hasError()) {
             $aModule = $oModule->asArray($this->_parameters, $files);
             //append files to exported module datas
             $aModule['files'] = array();
             if ($files) {
                 $aModule['files'] = $files;
             }
             //create export datas
             $aExport = array('version' => AUTOMNE_VERSION, 'language' => $cms_language->getCode(), 'description' => isset($this->_parameters['description']) ? $this->_parameters['description'] : '', 'modules' => array($aModule));
         }
         $return = '';
         switch ($format) {
             case 'php':
                 $return = $aExport;
                 break;
             case 'xml':
                 $array2Xml = new CMS_array2Xml($aExport, "export");
                 $return = $array2Xml->getXMLString();
                 break;
             case 'patch':
                 //create patch datas
                 $archiveFile = PATH_TMP_FS . '/' . $this->_module . '-' . date('Ymd-His') . '.tgz';
                 $archive = new CMS_gzip_file(substr($archiveFile, strlen(PATH_REALROOT_FS) + 1));
                 $archive->set_options(array('basedir' => PATH_REALROOT_FS . '/'));
                 if (isset($aExport['modules'])) {
                     foreach ($aExport['modules'] as $moduleDatas) {
                         if (isset($moduleDatas['files'])) {
                             foreach ($moduleDatas['files'] as $file) {
                                 if (file_exists(PATH_REALROOT_FS . $file)) {
                                     $archive->add_files(array(substr($file, 1)));
                                 }
                             }
                         }
                     }
                 }
                 $array2Xml = new CMS_array2Xml($aExport, "export");
                 $sOutput = $array2Xml->getXMLString();
                 $datas = new CMS_file(PATH_REALROOT_FS . '/export.xml');
                 $datas->setContent($sOutput);
                 $datas->writeToPersistence();
                 $archive->add_files(array('export.xml'));
                 //create archive
                 if ($archive->create_archive()) {
                     $return = $archiveFile;
                 } else {
                     $this->raiseError('Error during archive creation ...');
                 }
                 //delete tmp file
                 $datas->delete();
                 break;
             default:
                 $this->raiseError('Unknown format : ' . $format);
                 return false;
                 break;
         }
     }
     return $return;
 }
Beispiel #3
0
function patch($patchFile, &$error)
{
    $archive = new CMS_gzip_file($patchFile);
    if (!$archive->hasError()) {
        $archive->set_options(array('basedir' => PATH_TMP_FS . "/", 'overwrite' => 1, 'level' => 1, 'dontUseFilePerms' => 1, 'forceWriting' => 1));
        if (is_dir(PATH_TMP_FS)) {
            if (!method_exists($archive, 'extract_files') || !$archive->extract_files()) {
                $error = 'Error : Extraction error...';
                return false;
            }
        } else {
            $error = 'Error : Extraction directory does not exist';
            return false;
        }
    } else {
        $error = 'Error : Unable to extract archive wanted ' . $filename . '. It is not a valid format...';
        return false;
    }
    if (!$archive->hasError()) {
        unset($archive);
    } else {
        $error = 'Extraction error...';
        return false;
    }
    //Check files content
    $automnePatch = new CMS_patch();
    //read patch param file and check versions
    $patchFile = new CMS_file(PATH_TMP_FS . "/patch");
    if ($patchFile->exists()) {
        $patch = $patchFile->readContent("array");
    } else {
        $error = 'Error : File ' . PATH_TMP_FS . '/patch does not exists ...';
        return false;
    }
    if (!$automnePatch->checkPatch($patch)) {
        $error = 'Error : Patch does not match current version ...';
        return false;
    }
    //read install param file and do maximum check on it before starting the installation process
    $installFile = new CMS_file(PATH_TMP_FS . "/install");
    if ($installFile->exists()) {
        $install = $installFile->readContent("array");
    } else {
        $error = 'Error : File ' . PATH_TMP_FS . '/install does not exists ...';
        return false;
    }
    $installError = $automnePatch->checkInstall($install, $errorsInfos);
    if ($installError) {
        $error = 'Error : Invalid install file :';
        $error .= $installError;
        return false;
    }
    //start Installation process
    $automnePatch->doInstall($install);
    $installError = false;
    $return = $automnePatch->getReturn();
    foreach ($return as $line) {
        if ($line['type'] == 'report') {
            $error .= $line['text'];
        }
    }
    if ($installError) {
        $error = 'Error during installation process : ' . $error;
        return false;
    }
    //remove temporary files
    !CMS_file::deltree(PATH_TMP_FS);
    return true;
}