/** * Gets the array of the $has_one vars on this component * * @return BedrockNode */ public function getHasOneVars() { $v = parent::getHasOneVars(); $has_one = $v ? $v->getConfiguration() : array(); foreach (SilverSmithProject::get_all_nodes() as $node) { if ($components = $node->getComponents()) { if ($me = $components->get($this->key)) { if ($me->getType() == "many") { $has_one[$node->key] = $node->key; } } } } return empty($has_one) ? false : new BedrockNode("Root", $has_one, "Root"); }
/** * Gets an array of $belongs_many_many vars for the generated code, in $RelationName => $ClassName pairs * * @return BedrockNode */ public function getBelongsManyManyVars() { $belongs = array(); foreach (SilverSmithProject::get_all_nodes() as $node) { if ($components = $node->getComponents()) { if ($me = $components->get($this->key)) { if ($me->getType() == "manymany") { $belongs[SilverSmithUtil::pluralize($node->getKey())] = $node->getKey(); } } } } return empty($belongs) ? false : new BedrockNode("Root", $belongs, "Root"); }
/** * Creates and updates the PHP code for all classes defined in the SilverSmith project configuration file * * @see "silversmith help" * @param The parameters, e.g. from the command line */ public static function build_code($params = array()) { state("Validating project definition..."); $validator = new SilverSmithSpec_Validator(self::$yaml_path); $errors = $validator->getErrors(); if (!empty($errors)) { say(error("Validation error!")); say("Please fix the following errors:"); foreach ($errors as $e) { say(" -- " . $e); } say("Execution terminated by validation errors."); die; } else { state("OK\n"); } $page_types = 0; $page_types_created = 0; $page_types_updated = 0; $components = 0; $components_created = 0; $components_updated = 0; $decorators = array(); line(); say(cell("Status", 11, true, "grey", "on_white") . cell("File", 30, true, "grey", "on_white") . cell("Result", 50, true, "grey", "on_white")); foreach (SilverSmithProject::get_all_nodes() as $node) { if (!$node->isNew() && !$node->isSilverSmithed()) { say(cell("Omitted", 11, true, "white", "on_red") . cell("{$node->getKey()}.php", 30) . cell("Class has no code delimiters", 50)); continue; } $class = $node->getKey(); if ($node->getDecorator()) { $decorators[] = $node->getKey(); $class .= "Decorator"; } $type = $node->getContentType(); if ($type == "PageType") { $page_types++; } elseif ($type == "Component") { $components++; } $new = $node->isNew(); if (!$new) { $diff = $node->updateFile(); } else { $node->createFile(); } if ($new) { $new_fields = 0; $new_components = 0; if ($node->getFields()) { $new_fields = $node->getFields()->size(); } if ($node->getComponents()) { $new_components = $node->getComponents()->size(); } say(cell("Created", 11, true, "white", "on_green") . cell("{$class}.php", 30) . cell("{$new_fields} fields and {$new_components} components.", 50)); if ($type == "PageType") { $page_types_created++; } elseif ($type == "Component") { $components_created++; } } else { if (!$diff) { say(cell("Unchanged", 11, true, "grey", "on_yellow") . cell("{$class}.php", 30) . cell("No modifications", 50)); } else { say(cell("Updated", 11, true, "white", "on_blue") . cell("{$class}.php", 30) . cell(sprintf("%d change(s), %d insertion(s), %d deletion(s)", $diff['changed'], $diff['added'], $diff['deleted']), 50)); if ($type == "PageType") { $page_types_updated++; } elseif ($type == "Component") { $components_updated++; } } } } state("Rebuilding database..."); self::rebuild_manifest(); $db = self::rebuild_database(); say("done."); $tables_created = 0; $fields_created = 0; foreach ($db as $table_name => $settings) { if ($settings['created']) { $tables_created++; } $fields_created += sizeof($settings['fields']); } if ($tables_created > 0) { say("{$tables_created} tables created", "green", "bold"); } if ($fields_created > 0) { say("{$fields_created} fields created", "green", "bold"); } if (sizeof($db) > 0) { line(); } foreach ($db as $table_name => $settings) { if ($settings['created']) { say($table_name, "green", "bold"); } else { say($table_name); } foreach ($settings['fields'] as $field) { say("+ {$field}"); } state("\n"); } line(); state("Done"); say("\n\n"); say("Success! ", "green", "bold"); say("\n\n"); say(cell("", 50) . cell("Created", 10, true, "white", "on_green") . cell("Updated", 10, true, "white", "on_blue") . cell("Total", 10, true, "white", "on_red")); say(cell("Page types:", 50) . cell($page_types_created, 10) . cell($page_types_updated, 10) . cell($page_types, 10)); if (isset($params['debug'])) { say("Debug output:", "cyan"); say(self::$debug_output); } }