/** * 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; }
/** * 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(); }
/** * 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(); }