Exemple #1
0
 /**
  * Run AutoMOD Tests.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function automod()
 {
     if (!$this->contrib->type->automod_test) {
         return $this->helper->error('INVALID_TOOl');
     }
     $this->package->ensure_extracted();
     // Start up the machine
     $prevalidator = $this->contrib->type->get_prevalidator();
     // Automod testing time
     $details = '';
     $html_results = $bbcode_results = array();
     $this->revision->load_phpbb_versions();
     foreach ($this->revision->phpbb_versions as $row) {
         $version_string = $row['phpbb_version_branch'][0] . '.' . $row['phpbb_version_branch'][1] . '.' . $row['phpbb_version_revision'];
         $phpbb_path = $prevalidator->get_helper()->prepare_phpbb_test_directory($version_string);
         if ($phpbb_path === false) {
             continue;
         }
         $this->template->assign_vars(array('PHPBB_VERSION' => $version_string, 'TEST_ID' => $row['row_id']));
         $html_result = $bbcode_result = '';
         $prevalidator->run_automod_test($this->package, $phpbb_path, $details, $html_result, $bbcode_result);
         $bbcode_results[] = $bbcode_result;
     }
     $bbcode_results = $this->get_result_post('VALIDATION_AUTOMOD', implode("\n\n", $bbcode_results));
     // Update the queue with the results
     $post = $this->queue->topic_reply($bbcode_results);
     $this->package->cleanup();
     redirect($post->get_url());
 }
 /**
  * Extract style package to demo board.
  *
  * @return null
  */
 public function extract_package()
 {
     $this->package->ensure_extracted();
     $package_root = $this->package->find_directory(array('files' => array('required' => 'style.cfg')));
     $style_root = $this->get_style_dir();
     $filesystem = new \Symfony\Component\Filesystem\Filesystem();
     $filesystem->remove($style_root);
     $filesystem->rename($this->package->get_temp_path() . '/' . $package_root, $style_root);
 }
Exemple #3
0
 /**
  * Extract style package to demo board.
  *
  * @return null
  */
 public function extract_package()
 {
     $this->package->ensure_extracted();
     $package_root = $this->package->find_directory(array('files' => array('required' => 'style.cfg')));
     $style_root = $this->get_style_dir();
     $filesystem = new \Symfony\Component\Filesystem\Filesystem();
     $filesystem->remove($style_root);
     // Only copy necessary files
     $finder = new Finder();
     $finder->ignoreVCS(false)->ignoreDotFiles(false)->files()->notName('/\\.(svg|png|jpe?g|gif|html|js|css|cfg)$/i')->in($this->package->get_temp_path());
     $filesystem->remove($finder);
     $filesystem->rename($this->package->get_temp_path() . '/' . $package_root, $style_root);
 }
 /**
  * Repack extension to add version check info and match
  * correct directory structure to given ext name.
  *
  * @param package $package
  * @param \titania_contribution $contrib
  * @pram \titania_revision $revision
  * @throws \Exception if an error occurred
  */
 protected function repack(package $package, \titania_contribution $contrib, \titania_revision $revision)
 {
     $package->ensure_extracted();
     $ext_base_path = $package->find_directory(array('files' => array('required' => 'composer.json', 'optional' => 'ext.php')), 'vendor');
     if ($ext_base_path === null) {
         throw new \Exception($this->root_not_found_key);
     }
     $composer_file = $package->get_temp_path() . '/' . $ext_base_path . '/composer.json';
     $data = $this->get_composer_data($composer_file);
     if (!is_array($data) || empty($data['name']) || !$this->validate_ext_name($data['name'])) {
         throw new \Exception('INVALID_EXT_NAME');
     }
     $ext_name = $data['name'];
     $data = $this->update_phpbb_requirement($data);
     $data = $this->set_version_check($data, $contrib);
     $data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     file_put_contents($composer_file, $data);
     $package->restore_root($ext_base_path, $ext_name);
     $package->repack($this->clean_package);
     $revision->revision_composer_json = $data;
     $contrib->contrib_package_name = $ext_name;
     $contrib->submit();
 }
 /**
  * Checks the file for the array contents
  * Make sure it has all the keys present in the newest version
  *
  * @param \phpbb\titania\entity\package $package
  * @param string $reference_filepath The path to the files against I want to validate the uploaded package
  * @return array Returns an array of error messages encountered
  */
 public function check_package($package, $reference_filepath)
 {
     $package->ensure_extracted();
     $error = $missing_keys = array();
     // Basically the individual parts of the translation, we check them separately, because they have colliding filenames
     $types = array('language' => 'language/', 'prosilver' => 'styles/prosilver/imageset/en', 'subsilver2' => 'styles/subsilver2/imageset/en');
     // Do the check for all types
     foreach ($types as $type => $path) {
         // Get all the files present in the uploaded package for the currently iterated type
         $uploaded_files = $this->lang_filelist($package->get_temp_path());
         $reference_files = $this->lang_filelist($reference_filepath);
         ksort($uploaded_files);
         ksort($reference_files);
         switch ($type) {
             case 'language':
                 // The uploaded files array has keys prefixed with the upload path of the contribution
                 // Have it stored in the variable so we can work with it
                 $uploaded_files_prefix = explode('/', key($uploaded_files));
                 $iso_code = $uploaded_files_prefix[2];
                 $uploaded_files_prefix = $package->get_temp_path() . '/' . $uploaded_files_prefix[0];
                 // This goes directly to the root of the uploaded language pack, like /upload_path/language/cs/
                 $uploaded_lang_root = $uploaded_files_prefix . '/language/' . $iso_code . '/';
                 // Just perform a basic check if the common file is there
                 if (!is_file($uploaded_lang_root . 'common.php')) {
                     return array($this->user->lang('NO_TRANSLATION'));
                 }
                 // Loop through the reference files
                 foreach ($reference_files as $dir => $files) {
                     // Do not loop through files which are in non-language directories
                     if (strpos($dir, $path) === 0) {
                         // Loop through the files in the language/, language/adm etc. directories
                         foreach ($files as $file) {
                             $exists = true;
                             $uploaded_file_path = str_replace('/en/', '/' . $iso_code . '/', $uploaded_files_prefix . '/' . $dir . $file);
                             $ext = strtolower(substr($file, -3));
                             // Require php and txt files
                             if ($ext == 'php' || $ext == 'txt') {
                                 if (!is_file($uploaded_file_path)) {
                                     $error[] = $this->user->lang('MISSING_FILE', str_replace('/en/', '/' . $iso_code . '/', $dir . $file));
                                     // report a missing file
                                     $exists = false;
                                 }
                             }
                             // If the file is a php file and actually exists, no point in checking keys in a nonexistent one
                             if ($ext == 'php' && $exists) {
                                 $missing_keys[$dir . $file] = $this->check_missing_keys($reference_filepath . '' . $dir . $file, $uploaded_file_path);
                             }
                             // In the last step we have removed the license and index files if there were any. We'll just put a new one instead
                             $this->add_license_files($uploaded_lang_root . '/LICENSE', $reference_filepath);
                             $this->add_htm_files($uploaded_lang_root, $reference_filepath);
                         }
                     }
                 }
                 if (sizeof($missing_keys)) {
                     foreach ($missing_keys as $file => $keys) {
                         if (sizeof($keys)) {
                             $error[] = $this->user->lang('MISSING_KEYS', $file, implode('<br />', $keys));
                         }
                     }
                 }
                 break;
             case 'prosilver':
             case 'subsilver2':
                 // just let them go through atm...
                 break;
         }
     }
     // We are going to check if all files included in the language pack are allowed
     // Before we need some stuff
     // We construct a list of all reference files with complete structure
     foreach ($reference_files as $dir => $files) {
         if (strpos($dir, $types['language']) === 0 || strpos($dir, $types['prosilver']) === 0 || strpos($dir, $types['subsilver2']) === 0) {
             foreach ($files as $file) {
                 $list_reference_files[] = $dir . $file;
             }
         }
     }
     // We construct a list of all uploaded file with complete structure
     foreach ($uploaded_files as $dir => $files) {
         // We need to clean our directory path according the type and replace iso_code package by en
         if (strpos($dir, $types['language']) != 0) {
             $dir_prefix = explode($types['language'], $dir);
         } else {
             if (strpos($dir, $types['prosilver']) != 0) {
                 $dir_prefix = explode($types['prosilver'], $dir);
             } else {
                 if (strpos($dir, $types['subsilver2']) != 0) {
                     $dir_prefix = explode($types['subsilver2'], $dir);
                 }
             }
         }
         $dir_clean = str_replace('/' . $iso_code . '/', '/en/', str_replace($dir_prefix[0], '', $dir));
         foreach ($files as $file) {
             $list_uploaded_files[] = $dir_clean . $file;
         }
     }
     // It's time to check if each file uploaded in the package is allowed
     foreach ($list_uploaded_files as $file) {
         if (!in_array($file, $list_reference_files) && !in_array($file, $this->ignore_files)) {
             $error[] = $this->user->lang('WRONG_FILE', str_replace('/en/', '/' . $iso_code . '/', $file));
             // report a wrong file
         }
     }
     if (!sizeof($error)) {
         $package->repack();
         // we have made changes to the package, so replace the original zip file
     }
     return $error;
 }
Exemple #6
0
 /**
  * AutoMOD Test.
  *
  * @param \titania_contribution $contrib
  * @param \titania_revision $revision
  * @param attachment $attachment
  * @param string $download_package
  * @param package $package
  * @param template $template
  * @return array
  */
 public function automod_test(\titania_contribution $contrib, \titania_revision $revision, attachment $attachment, $download_package, package $package, template $template)
 {
     $package->ensure_extracted();
     $prevalidator = $this->get_prevalidator();
     // Automod testing time
     $details = '';
     $error = $html_results = $bbcode_results = array();
     if (!$revision->phpbb_versions) {
         $revision->load_phpbb_versions();
     }
     foreach ($revision->phpbb_versions as $row) {
         $version_string = $row['phpbb_version_branch'][0] . '.' . $row['phpbb_version_branch'][1] . '.' . $row['phpbb_version_revision'];
         $phpbb_path = $prevalidator->get_helper()->prepare_phpbb_test_directory($version_string);
         if ($phpbb_path === false) {
             $error = array_merge($error, $prevalidator->get_helper()->get_errors());
             continue;
         }
         $template->assign_vars(array('PHPBB_VERSION' => $version_string, 'TEST_ID' => $row['row_id']));
         $html_result = $bbcode_result = '';
         $installed = $prevalidator->run_automod_test($package, $phpbb_path, $details, $html_result, $bbcode_result);
         $html_results[] = $html_result;
         $bbcode_results[] = $bbcode_result;
     }
     if (is_array($details)) {
         $revision->install_time = $details['INSTALLATION_TIME'];
         switch ($details['INSTALLATION_LEVEL']) {
             case 'easy':
                 $revision->install_level = 1;
                 break;
             case 'intermediate':
                 $revision->install_level = 2;
                 break;
             case 'advanced':
                 $revision->install_level = 3;
                 break;
         }
         $revision->submit();
     }
     $html_results = implode('<br /><br />', $html_results);
     $bbcode_results = implode("\n\n", $bbcode_results);
     // Update the queue with the results
     $queue = $revision->get_queue();
     $queue->automod_results = $bbcode_results;
     $queue->submit();
     $template->assign_var('AUTOMOD_RESULTS', $html_results);
     return array('error' => $error);
 }