예제 #1
0
 public function extract()
 {
     $tmp_dir = Core_Model_Directory::getTmpDirectory(true) . '/';
     if (!is_writable($tmp_dir)) {
         throw new Exception($this->_("The folder %s is not writable. Please fix this issue and try again.", $tmp_dir));
     } else {
         if (is_dir($this->_tmp_directory)) {
             Core_Model_Directory::delete($this->_tmp_directory);
         }
         mkdir($this->_tmp_directory, 0777);
         exec('unzip "' . $this->_tmp_file . '" -d "' . $this->_tmp_directory . '" 2>&1', $output);
         if (!count(glob($this->_tmp_directory))) {
             throw new Exception($this->_("Unable to extract the archive. Please make sure that the 'zip' extension is installed."));
         }
         exec('unzip "' . $this->_tmp_file . '" -d "' . $this->_tmp_directory . '" 2>&1', $output);
         $base_path = $this->_tmp_directory . "/app/modules/Template/db";
         if (file_exists("{$base_path}/database.template.php")) {
             $template = new Installer_Model_Installer_Module();
             $template->find("Template", "name");
             $tmp_new_version = explode(".", $template->getVersion());
             if (count($tmp_new_version) > 3) {
                 $version = "{$tmp_new_version[0]}.{$tmp_new_version[1]}.{$tmp_new_version[2]}." . ($tmp_new_version[3] + 1);
             } else {
                 $version = "{$template->getVersion()}.1";
             }
             $file = "database.{$version}.php";
             rename("{$base_path}/database.template.php", "{$base_path}/{$file}");
         }
         return $this->_tmp_directory;
     }
     /*
             $zip = new ZipArchive();
             if($zip->open($this->_tmp_file)) {
                 $tmp_dir = Core_Model_Directory::getTmpDirectory(true).'/';
                 if(!is_writable($tmp_dir)) {
                     throw new Exception($this->_("The folder %s is not writable. Please fix this issue and try again.", $tmp_dir));
                 } else {
     
                     if(is_dir($this->_tmp_directory)) {
                         Core_Model_Directory::delete($this->_tmp_directory);
                     }
                     mkdir($this->_tmp_directory, 0777);
     
                     if($zip->extractTo($this->_tmp_directory)) {
                         $zip->close();
                         return $this->_tmp_directory;
                     } else {
                         throw new Exception($this->_("Unable to open the file. Please, make sure that you sent a valid archive."));
                     }
                 }
     
             } else {
                 throw new Exception($this->_("Unable to open the archive."));
             }
     */
 }