Beispiel #1
0
 /**
  * Clean attachment package.
  *
  * @return array Returns array containing any errors encountered.
  */
 protected function clean_package()
 {
     $error = array();
     if (!$this->contrib->type->restore_root && !$this->contrib->type->clean_package) {
         return $error;
     }
     $root_directory = null;
     if ($this->contrib->type->restore_root && is_array($this->contrib->type->root_search)) {
         $search = $this->contrib->type->root_search;
         $exclude = !empty($search['exclude']) ? $search['exclude'] : null;
         unset($search['exclude']);
         $root_directory = $this->package->find_directory($search, $exclude);
         if ($root_directory === null) {
             $error[] = $this->user->lang($this->contrib->type->root_not_found_key);
         }
     }
     if (empty($error)) {
         if ($root_directory !== null) {
             // Adjust package name to follow naming conventions
             $new_root_name = $this->contrib->type->fix_package_name($this->contrib, $this->revision, $this->attachment, $root_directory);
             $this->package->restore_root($root_directory, $new_root_name);
         }
         // Replace the uploaded zip package with the new one
         $this->package->repack($this->contrib->type->clean_package);
         $this->update_package_stats();
     }
     // Remove our temp files
     $this->package->cleanup();
     return $error;
 }
Beispiel #2
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());
 }
 /**
  * Get composer.json contents from a zip file.
  *
  * @param string $file Path to the zip file
  * @return string Returns the content of the composer.json
  */
 protected function get_composer_json($file)
 {
     $path = $this->package->set_source($file)->set_temp_path($this->ext_config->__get('contrib_temp_path'), true)->extract()->find_directory(array('files' => array('required' => 'composer.json')), 'vendor');
     $composer_json = '';
     if ($path !== null) {
         $composer_json = file_get_contents($this->package->get_temp_path() . '/' . $path . '/composer.json');
     }
     $this->package->cleanup();
     return $composer_json;
 }
Beispiel #4
0
 /**
  * Generate Composer package.
  *
  * @param string $composer_package Path to package destination
  */
 protected function generate_composer_package($composer_package)
 {
     $package = new package();
     $package->set_source($this->ext_config->upload_path . $this->file['physical_filename']);
     $package->set_temp_path($this->ext_config->contrib_temp_path, true);
     $ext_base_path = $package->find_directory(array('files' => array('required' => 'composer.json', 'optional' => 'ext.php')), 'vendor');
     $package->restore_root($ext_base_path, $this->id);
     $filesystem = new Filesystem();
     $filesystem->copy($package->get_source(), $this->ext_config->upload_path . $composer_package);
     $package->set_source($package->get_source() . '.composer');
     $package->repack(true);
     $package->cleanup();
 }
Beispiel #5
0
 /**
  * @{inheritDoc}
  */
 public function upload_check(attachment $attachment)
 {
     $package = new package();
     $package->set_source($attachment->get_filepath())->set_temp_path($this->ext_config->__get('contrib_temp_path'), true)->extract();
     $license_location = $package->find_directory(array('files' => array('required' => 'license.txt')));
     $package->cleanup();
     if ($license_location !== null && substr_count($license_location, '/') < 2) {
         return array();
     }
     return array($this->user->lang('LICENSE_FILE_MISSING'));
 }