コード例 #1
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $dialog = $this->getHelperSet()->get('dialog');
     $_configuration = $this->getHelper('configuration')->getConfiguration();
     $file = $input->getArgument('file');
     $connection = $this->getHelper('configuration')->getConnection();
     if (is_file($file) && is_readable($file)) {
         $phar = new \PharData($file);
         if ($phar->hasMetadata()) {
             $langInfo = $phar->getMetadata();
             $connection = $this->getHelper('configuration')->getConnection();
             if ($connection) {
                 $q = mysql_query("SELECT * FROM language WHERE dokeos_folder = '{$langInfo['dokeos_folder']}' ");
                 $langInfoFromDB = mysql_fetch_array($q, MYSQL_ASSOC);
                 $langFolderPath = $_configuration['root_sys'] . 'main/lang/' . $langInfoFromDB['dokeos_folder'];
                 if ($langInfoFromDB && $langFolderPath) {
                     //Overwrite lang files
                     if (!$dialog->askConfirmation($output, '<question>The ' . $langInfo['original_name'] . ' language already exists in Chamilo. Did you want to overwrite the contents? (y/N)</question>', false)) {
                         return;
                     }
                     if (is_writable($langFolderPath)) {
                         $output->writeln("Trying to save files here: {$langFolderPath}");
                         $phar->extractTo($langFolderPath, null, true);
                         // extract all files
                         $output->writeln("Files were copied.");
                     } else {
                         $output->writeln("<error>Make sure that this folder {$langFolderPath} has writable permissions or execute the script with sudo </error>");
                     }
                 } else {
                     //Check if parent_id exists
                     $parentId = '';
                     if (!empty($langInfo['parent_id'])) {
                         $sql = "select selected_value from settings_current where variable = 'allow_use_sub_language'";
                         $result = mysql_query($sql);
                         $subLanguageSetting = mysql_fetch_array($result, MYSQL_ASSOC);
                         $subLanguageSetting = $subLanguageSetting['selected_value'];
                         if ($subLanguageSetting == 'true') {
                             $q = mysql_query("SELECT * FROM language WHERE id = '{$langInfo['parent_id']}' ");
                             $parentLangInfoFromDB = mysql_fetch_array($q, MYSQL_ASSOC);
                             if ($parentLangInfoFromDB) {
                                 $output->writeln("Setting parent language: " . $parentLangInfoFromDB['original_name']);
                                 $parentId = $langInfo['parent_id'];
                             } else {
                                 $output->writeln("The lang parent_id = {$langInfo['parent_id']} does not exist in Chamilo. Try to import first the parent language.");
                                 exit;
                             }
                         } else {
                             $output->writeln("<comment>Please turn ON the sublanguage feature in this portal</comment>");
                             exit;
                         }
                     } else {
                         $output->writeln("Parent language was not provided");
                     }
                     $q = mysql_query("INSERT INTO language (original_name, english_name, isocode, dokeos_folder, available, parent_id) VALUES (\n                                '" . $langInfo['original_name'] . "',\n                                '" . $langInfo['english_name'] . "',\n                                '" . $langInfo['isocode'] . "',\n                                '" . $langInfo['dokeos_folder'] . "',\n                                '1',\n                                '" . $parentId . "')");
                     if ($q) {
                         $output->writeln("Language inserted in the DB");
                         $langFolderPath = $_configuration['root_sys'] . 'main/lang/' . $langInfo['dokeos_folder'];
                         $phar->extractTo($langFolderPath, null, true);
                         // extract all files
                         $output->writeln("<comment>Files were copied here {$langFolderPath} </comment>");
                     } else {
                         $output->writeln("An error ocurred while tring to create the language");
                     }
                 }
             }
         } else {
             $output->writeln("<comment>The file is not a valid Chamilo language package<comment>");
         }
     } else {
         $output->writeln("<comment>The file located in '{$file}' is not accessible<comment>");
     }
 }
コード例 #2
0
ファイル: Cloner.php プロジェクト: peopleplan/Pyrus
 function toZip()
 {
     if (isset($this->zip)) {
         return;
     }
     if (file_exists($this->file . '.zip')) {
         try {
             $p = new \PharData($this->file . '.zip');
         } catch (\Exception $e) {
         }
         if ($p->getMetadata() && is_string($p->getMetadata()) && isset($p[$p->getMetadata()])) {
             if (isset($this->tar)) {
                 $test = $this->tar;
             } elseif (isset($this->tgz)) {
                 $test = $this->tgz;
             } else {
                 $test = $this->phar;
             }
             if ($p->getMetadata() === $test->getMetadata()) {
                 try {
                     // do both store the same package.xml and are they
                     // identical package.xml?
                     if ($p[$p->getMetadata()]->getContent() == $test[$p->getMetadata()]->getContent()) {
                         $this->zip = $p;
                         // yes
                         if ($this->outfile) {
                             copy($this->file . '.zip', $this->outfile . '.zip');
                         }
                         return;
                     }
                 } catch (\Exception $e) {
                 }
             }
         }
         unset($p);
         \Phar::unlinkArchive($this->file . '.zip');
     }
     if (isset($this->tar)) {
         if (file_exists($this->file . '.zip')) {
             \Phar::unlinkArchive($this->file . '.zip');
             unlink($this->file . '.zip');
         }
         $this->zip = $this->tar->convertToData(\Phar::ZIP, \Phar::NONE, $this->ext . '.zip');
         if ($this->outfile) {
             copy($this->file . '.zip', $this->outfile . '.zip');
         }
         $this->tar = new \PharData($this->file . '.tar');
         return;
     }
     if (isset($this->tgz)) {
         if (file_exists($this->file . '.zip')) {
             \Phar::unlinkArchive($this->file . '.zip');
             unlink($this->file . '.zip');
         }
         $this->zip = $this->tgz->convertToData(\Phar::ZIP, \Phar::NONE, $this->ext . '.zip');
         if ($this->outfile) {
             copy($this->file . '.zip', $this->outfile . '.zip');
         }
         $this->tgz = new \PharData($this->file . '.tgz');
         return;
     }
     // by process of elimination, the phar is in phar format
     if (file_exists($this->file . '.zip')) {
         \Phar::unlinkArchive($this->file . '.zip');
         unlink($this->file . '.zip');
     }
     $this->zip = $this->phar->convertToData(\Phar::ZIP, \Phar::NONE, $this->ext . '.zip');
     if ($this->outfile) {
         copy($this->file . '.zip', $this->outfile . '.zip');
     }
     $this->phar = new \Phar($this->file . '.phar');
 }