コード例 #1
0
ファイル: SyncCtoUpdater.php プロジェクト: menatwork/synccto
 /**
  * Build a zip with all files.
  * 
  * @param string $strZipPath Path for the file
  * @throws Exception 
  */
 public function buildUpdateZip($strZipPath)
 {
     // Open archive
     $this->objZipArchive = new ZipArchiveCto();
     if (($mixError = $this->objZipArchive->open($strZipPath, ZipArchiveCto::CREATE)) !== true) {
         throw new Exception($GLOBALS['TL_LANG']['MSC']['error'] . ": " . $this->objZipArchive->getErrorDescription($mixError));
     }
     // Add files
     $this->addFiles();
     // Add db update file
     $this->addDatabase();
     $this->objZipArchive->close();
 }
コード例 #2
0
 /**
  * Update the database.
  */
 protected function updateDatabase($strZipPath)
 {
     $arrError = array();
     // New archive
     $objZipArchive = new ZipArchiveCto();
     // Open archive
     if (($mixError = $objZipArchive->open($strZipPath, ZipArchiveCto::CREATE)) !== true) {
         throw new Exception($GLOBALS['TL_LANG']['MSC']['error'] . ": " . $objZipArchive->getErrorDescription($mixError));
     }
     // Read XML
     $xmlReader = new XMLReader();
     $xmlReader->XML($objZipArchive->getFromName("SQL/sql.xml"));
     // Init tmp vars
     $strTableName = "";
     $arrFieldList = array();
     $arrDefList = array();
     $strOptions = array();
     while ($xmlReader->read()) {
         switch ($xmlReader->nodeType) {
             case XMLReader::ELEMENT:
                 switch ($xmlReader->localName) {
                     case "table":
                         $strTableName = $xmlReader->getAttribute("name");
                         $arrFieldList = array();
                         $arrDefList = array();
                         break;
                     case "field":
                         $arrFieldList[$xmlReader->getAttribute("name")] = $xmlReader->readString();
                         break;
                     case "def":
                         $arrDefList[$xmlReader->getAttribute("name")] = $xmlReader->readString();
                         break;
                     case "option":
                         $strOptions = $xmlReader->readString();
                         break;
                 }
                 break;
             case XMLReader::END_ELEMENT:
                 switch ($xmlReader->localName) {
                     case "table":
                         $mixResult = $this->compareDatabase($strTableName, $arrFieldList, $arrDefList, $strOptions);
                         if ($mixResult !== true && is_array($mixResult)) {
                             $arrError = array_merge($arrError, $mixResult);
                         }
                         break;
                 }
                 break;
         }
     }
     if (count($arrError) == 0) {
         return true;
     } else {
         return $arrError;
     }
 }
コード例 #3
0
ファイル: SyncCtoFiles.php プロジェクト: menatwork/synccto
 /**
  * Unzip files
  *
  * @param string $strRestoreFile Path to the zip file
  * @return mixes True - If ervething is okay, Array - If some files could not be extract to a given path.
  * @throws Exception if the zip file was not able to open.
  */
 public function runRestore($strRestoreFile)
 {
     $objZipArchive = new ZipArchiveCto();
     if (($mixError = $objZipArchive->open($strRestoreFile)) !== true) {
         $strError = sprintf("%s %s || Status (%s): %s || System (%s): %s  ", $GLOBALS['TL_LANG']['ERR']['cant_extract_file'], $objZipArchive->getErrorDescription($mixError), $objZipArchive->status, $objZipArchive->getErrorDescription($objZipArchive->status), $objZipArchive->statusSys, $objZipArchive->getErrorDescription($objZipArchive->statusSys));
         throw new \RuntimeException($strError);
     }
     if ($objZipArchive->numFiles == 0) {
         return;
     }
     $arrErrorFiles = array();
     for ($i = 0; $i < $objZipArchive->numFiles; $i++) {
         $filename = $objZipArchive->getNameIndex($i);
         if (!$objZipArchive->extractTo("/", $filename)) {
             $arrErrorFiles[] = $filename;
         }
     }
     $objZipArchive->close();
     if (count($arrErrorFiles) == 0) {
         return true;
     } else {
         return $arrErrorFiles;
     }
 }