/** * Add dependencies for the current spark current spark. * If you have a new unverified version of a spark, and you want to add it's * dependencies, pass the spec in here. * @param Spark_spec $spec */ public function processDependencies($spec) { # Make sure we're working with something usable $spec->validate(); # These will hold version ids $direct_dependencies = array(); $indirect_dependencies = array(); # Will hold the rows to be insterted into the db $dependency_rows = array(); if (count($spec->dependencies)) { # Make sure all the dependencies exist # If they do, keep track of the version_id in the direct dependants foreach ($spec->dependencies as $name => $version) { if (!($spark = self::get($name, $version))) { throw new SpecValidationException("The dependency '{$name}' version {$version} does not exist"); } $direct_dependencies[] = $spark->version_id; } # Get the dependencies of the dependencies, and add them to our own $this->db->select('needed_version_id'); $this->db->where_in('version_id', $direct_dependencies); $rows = $this->db->get('dependencies')->result(); # Anything that comes back is an indirect dependency, so let's # keep it separate foreach ($rows as $second_degree_dependency) { $version_id = $second_degree_dependency->needed_version_id; if (!in_array($version_id, $direct_dependencies)) { $indirect_dependencies[] = $version_id; } } # Add the direct dependency rows foreach ($direct_dependencies as $dependency) { $dependency_rows[] = array('version_id' => $this->version_id, 'needed_version_id' => $dependency, 'is_direct' => TRUE); } # Add the indrect dependency rows foreach ($indirect_dependencies as $dependency) { $dependency_rows[] = array('version_id' => $this->version_id, 'needed_version_id' => $dependency, 'is_direct' => FALSE); } # Insert the dependency information return $this->db->insert_batch('dependencies', $dependency_rows); } return TRUE; }
} elseif ($spark->repository_type == 'git') { $token = 'spark-' . $spark->id . '-' . time(); `git clone {$spark->base_location} {$tmp}`; `cd {$tmp} ; git checkout {$spark->tag} -b {$token} ; cd ..`; } else { echo "Unknown repo type ({$spark->repository_type}) for {$spark->name}.. skipping.\n"; $unsuccessful[] = $spark; continue; } # Switch back to the webroot chdir($webroot); try { # All or nothing. Verify versions aand insert dependencies atomically $CI->db->trans_begin(); # Load and validate the basics of the spark's YAML Spec $spec = Spark_spec::loadFromDirectory($tmp); # Check that everything looks with the spec on our end $spark->runPreSubmissionChecks($spec); # Add any dependencies in the spec $spark->processDependencies($spec); # Set the version $spark->setVersion($spec->version); # If there's a README file, store the contents $release = "{$spark->name}-{$spec->version}"; $release_dir = $spark_path . $spark->name; if ($readme = $spec->getReadme()) { $readme = file_get_contents($tmp . '/' . $readme); $spark->setVersionReadme($spec->version, $readme); } # Mark this spark as verified $spark->setVerified($spec->version, TRUE, base_url() . config_item('archive_path') . $spark->name . '/' . $release . ".zip");
<?php require_once dirname(__FILE__) . '/../libraries/spark_spec.php'; $args = $_SERVER['argv']; $script = $args[0]; if (count($args) != 2) { exit("Usage: php {$script} [SPARK-PATH]\n"); } $spark_path = rtrim($args[1], '/') . '/'; try { $spec = Spark_spec::loadFromDirectory($spark_path); } catch (Exception $ex) { exit("Validation failed: " . $ex->getMessage() . "\n"); } echo "Validation passed!\n";