Esempio n. 1
0
 public function generateAll()
 {
     $files = array();
     $error = $message = array();
     $use_errors = libxml_use_internal_errors(true);
     // Save error setting
     $xml_dir = $this->xml;
     $dirfiles = glob($xml_dir . '*.xml');
     foreach ($dirfiles as $path) {
         $file = str_replace($xml_dir, '', $path);
         if ($file != 'vqmod_opencart.xml') {
             $xml = simplexml_load_file($path);
             // XML Error handling
             if (!$xml) {
                 $error[] = $errmsg = sprintf($this->language->get('text_xml_not_valid'), $file);
                 $this->log(array(array('info' => array('modFile' => $file, 'id' => isset($xml->id) ? $xml->id : $file, 'version' => isset($xml->version) ? $xml->version : '', 'vqmver' => isset($xml->vqmver) ? $xml->vqmver : '', 'author' => isset($xml->author) ? $xml->author : ''), 'log' => $errmsg)));
             }
             libxml_clear_errors();
             if (isset($xml->file)) {
                 foreach ($xml->file as $file) {
                     $thefiles = explode(',', $file['name']);
                     foreach ($thefiles as $filename) {
                         $filename = (isset($file['path']) ? $file['path'] : '') . trim($filename);
                         if (!in_array($filename, $files)) {
                             $files[] = $filename;
                         }
                     }
                 }
             }
         }
     }
     libxml_use_internal_errors($use_errors);
     // Reset error setting
     $success = false;
     if ($files) {
         $this->deleteAll('cache');
         if (defined('SUBFOLDER') && defined('LOCALPATH')) {
             $tests = '../../';
         } else {
             $tests = $this->config->get('vqm_test');
         }
         //$VQMod = new VQMod();
         foreach ($files as $file) {
             $genfiles = glob('../' . $file);
             foreach ($genfiles as $file) {
                 $file = str_replace('../', '', $file);
                 $genfile = VQMod::modcheck($file);
                 if (is_file($genfile)) {
                     $newfile = $tests . $this->config->get('test_vqmod') . '/' . $file;
                     $success = $this->createFile($newfile);
                     // Pre-create file, to also get dirs in place
                     if ($success) {
                         $this->renameFile($genfile, $newfile);
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
 public function generateAll()
 {
     $tests = $this->config->get('vqmod_mod_test');
     if ($tests) {
         $files = $ofiles = $json = array();
         $use_errors = libxml_use_internal_errors(true);
         // Save error setting
         $xml_dir = '../vqmod/xml/';
         $dirfiles = glob($xml_dir . '*.xml');
         // Check all vQMod xml files for files to mod
         foreach ($dirfiles as $path) {
             $file = basename($path);
             if ($file != 'vqmod_opencart.xml') {
                 $xml = simplexml_load_file($path);
                 if (isset($xml->file)) {
                     foreach ($xml->file as $file) {
                         // Collect all the files to mod
                         $thefiles = explode(',', $file['name']);
                         foreach ($thefiles as $filename) {
                             $filename = (isset($file['path']) ? $file['path'] : '') . trim($filename);
                             if (!in_array($filename, $files)) {
                                 $files[] = $filename;
                             }
                         }
                     }
                 }
             }
         }
         libxml_use_internal_errors($use_errors);
         // Reset error setting
         $this->load->language('extension/modification');
         $this->load->model('extension/modification');
         // Refresh OCMOD files, clear vQMod files, and delete previous generated files
         $this->load->controller('extension/modification/refresh', true);
         $path = array('../' . $tests . 'modded/*');
         while (count($path) != 0) {
             $next = array_shift($path);
             foreach (glob($next) as $file) {
                 if (is_dir($file)) {
                     $path[] = $file . '/*';
                 }
                 $ofiles[] = $file;
             }
         }
         rsort($ofiles);
         $this->model_extension_modification->deleteFiles($ofiles);
         // Generate and copy vQMod files
         $success = $files ? false : true;
         if ($files) {
             foreach ($files as $file) {
                 $genfiles = glob('../' . $file);
                 foreach ($genfiles as $file) {
                     if (is_file($file)) {
                         $file = str_replace('../', '', $file);
                         $getfile = (file_exists(DIR_MODIFICATION . $file) ? DIR_MODIFICATION : '') . $file;
                         $genfile = VQMod::modcheck($getfile, $file);
                         if (is_file($genfile)) {
                             $newfile = $tests . 'modded/' . $file;
                             $success = $this->model_extension_modification->copyFile($genfile, $newfile, true);
                             if (!$success) {
                                 $json['error'] = 'Could not copy <b>' . $genfile . '</b> to <b>' . $newfile . '</b>';
                                 break 2;
                             }
                         }
                     }
                 }
             }
         }
         // Copy OCMod files to test folder (if not already there)
         if ($success) {
             $files = array();
             $path = array(DIR_MODIFICATION . '*');
             while (count($path) != 0) {
                 $next = array_shift($path);
                 foreach (glob($next) as $file) {
                     if (is_dir($file)) {
                         $path[] = $file . '/*';
                     } else {
                         $files[] = $file;
                     }
                 }
             }
             rsort($files);
             // Copy all modification files
             foreach ($files as $file) {
                 $newfile = str_replace(DIR_MODIFICATION, $tests . 'modded/', $file);
                 if ($file != DIR_MODIFICATION . 'index.html' && !file_exists('../' . $newfile) && is_file($file)) {
                     $success = $this->model_extension_modification->copyFile($file, $newfile, true);
                     if (!$success) {
                         $json['error'] = 'Could not copy <b>' . $file . '</b> to <b>' . $newfile . '</b>';
                         break;
                     }
                 }
             }
             if (!$json) {
                 $json['success'] = $this->language->get('text_generate_done');
             }
         }
         $this->model_extension_modification->doFTP(false);
     }
     $this->response->addHeader('Content-Type: application/json');
     $this->response->setOutput(json_encode($json));
 }