function do_action($test_mode = true) { $rel_id = relationship_id_of('page_to_feed_url'); $ext_url_id = id_of('external_url'); if ($ext_url_id == 0) { $external_url_fields = array('external_url' => array('url' => array('db_type' => 'tinytext'))); $ext_url_id = create_external_url_type($ext_url_id, 'External Url', 'external_url', 'External URLs', $external_url_fields); } if (empty($rel_id)) { echo '<p>page_to_feed_url does not yet exist.</p>'; if ($test_mode) { echo '<p>Would have created the allowable relationship page_to_feed_url</p>'; } else { $alrel_id = create_allowable_relationship(id_of('minisite_page'), $ext_url_id, 'page_to_feed_url', array('connections' => 'one_to_many', 'display_name' => 'Set up feed to display', 'description_reverse_direction' => 'Page(s) using this URL as the feed they display', 'description' => 'This relationship allows an external URL to be used as the feed source of an RSS parser/displayer')); if (!empty($alrel_id)) { echo '<p>created allowable relationship, id ' . $alrel_id . '</p>'; } } } else { echo '<p>page_to_feed_url already exists, so it does not need to be created.</p>'; } $rel_id = relationship_id_of('page_to_external_url'); if (!empty($rel_id)) { echo '<p>page_to_external_url still exists.</p>'; if ($test_mode) { echo '<p>Would have deleted the allowable relationship page_to_external_url</p>'; } else { if ($GLOBALS['sqler']->delete_one('allowable_relationship', $rel_id)) { echo '<p>deleted allowable relationship, id ' . $rel_id . '</p>'; } } } else { echo '<p>page_to_external_url no longer exists, so it does not need to be deleted.</p>'; } }
/** * Run the upgrader * @return string HTML report */ public function run() { $run_message = ''; if (!reason_relationship_name_exists('news_to_media_work')) { $news_to_media_work_definition = array('description' => 'News / Post shows Media Work', 'directionality' => 'bidirectional', 'connections' => 'many_to_many', 'required' => 'no', 'is_sortable' => 'yes', 'display_name' => 'Media', 'display_name_reverse_direction' => 'News / Posts'); if (create_allowable_relationship(id_of('news'), id_of('av'), 'news_to_media_work', $news_to_media_work_definition)) { $run_message .= '<p>Added the news_to_media_work allowable relationship.</p>'; } else { $run_message .= '<p>Failed to create the news_to_media_work allowable relationship. Try again. If you are not successful, you may wish to try to add this relationship type manually: In Master Admin, go to Allowable Relationship Manager, add a row, then create a relationship between News / Post and Media Work named news_to_media work. The other values are:</p>' . spray($news_to_media_work_definition); } } if (!reason_relationship_name_exists('event_to_media_work')) { $event_to_media_work_definition = array('description' => 'Event shows Media Work', 'directionality' => 'bidirectional', 'connections' => 'many_to_many', 'required' => 'no', 'is_sortable' => 'yes', 'display_name' => 'Media', 'display_name_reverse_direction' => 'Events'); if (create_allowable_relationship(id_of('event_type'), id_of('av'), 'event_to_media_work', $event_to_media_work_definition)) { $run_message .= '<p>Added the event_to_media_work allowable relationship.</p>'; } else { $run_message .= '<p>Failed to create the event_to_media_work allowable relationship. Try again. If you are not successful, you may wish to try to add this relationship type manually: In Master Admin, go to Allowable Relationship Manager, add a row, then create a relationship between Event and Media Work named event_to_media work. The other values are:</p>' . spray($event_to_media_work_definition); } } if (!empty($run_message)) { return $run_message; } else { return 'This update has already run.'; } }
function add_asset_to_category_relationship() { if (reason_relationship_name_exists('asset_to_category')) { echo '<p>asset_to_category already exists. No need to update.</p>' . "\n"; return false; } if ($this->mode == 'run') { $r_id = create_allowable_relationship(id_of('asset'), id_of('category_type'), 'asset_to_category', $this->asset_to_category_details); if ($r_id) { echo '<p>asset_to_category allowable relationship successfully created</p>' . "\n"; } else { echo '<p>Unable to create asset_to_category allowable relationship</p>'; echo '<p>You might try creating the relationship asset_to_category yourself in the reason administrative interface - it should include the following characteristics:</p>'; pray($this->asset_to_category_details); } } else { echo '<p>Would have created asset_to_category allowable relationship.</p>' . "\n"; } }
/** * Create the google map type. */ protected function create_google_map_type() { // make sure the cache is clear reason_refresh_relationship_names(); reason_refresh_unique_names(); $str = ''; $google_map_id = reason_create_entity(id_of('master_admin'), id_of('type'), $this->user_id(), 'Google Map', $this->google_map_type_details); create_default_rels_for_new_type($google_map_id); create_reason_table('google_map', $this->google_map_type_details['unique_name'], $this->user_id()); $ftet = new FieldToEntityTable('google_map', $this->google_map_table_fields); $ftet->update_entity_table(); ob_start(); $ftet->report(); $str .= ob_get_contents(); ob_end_clean(); // create all the necessary relationships for the google map type create_allowable_relationship(id_of('minisite_page'), id_of('google_map_type'), 'page_to_google_map', $this->page_to_google_map_details); create_allowable_relationship(id_of('event_type'), id_of('google_map_type'), 'event_to_google_map', $this->event_to_google_map_details); $str .= '<p>Created page_to_google_map and even_to_google_map allowable relationships</p>'; return $str; }
protected function create_course_relationships() { reason_refresh_unique_names(); // force refresh from the database just in case. $str = ''; if (!reason_relationship_name_exists('course_template_to_course_section')) { create_allowable_relationship(id_of('course_template_type'), id_of('course_section_type'), 'course_template_to_course_section', $this->template_to_section_details); $str .= '<p>Created template to section relationship.</p>'; } if (!reason_relationship_name_exists('course_template_to_page')) { create_allowable_relationship(id_of('course_template_type'), id_of('minisite_page'), 'course_template_to_page', $this->template_to_page_details); $str .= '<p>Created template to page relationship.</p>'; } if (!reason_relationship_name_exists('course_template_to_category')) { create_allowable_relationship(id_of('course_template_type'), id_of('category_type'), 'course_template_to_category', $this->template_to_category_details); $str .= '<p>Created template to category relationship.</p>'; } if (!reason_relationship_name_exists('course_section_to_category')) { create_allowable_relationship(id_of('course_section_type'), id_of('category_type'), 'course_section_to_category', $this->section_to_category_details); $str .= '<p>Created section to category relationship.</p>'; } return $str; }
function add_issue_to_css_url_relationship() { $r_id = relationship_id_of('issue_to_css_url'); if (!empty($r_id)) { echo '<p>issue_to_css_url already exists. No need to update.</p>' . "\n"; return; } if ($this->mode == 'run') { $r_id = create_allowable_relationship(id_of('issue_type'), id_of('external_url'), 'issue_to_css_url', array('description' => 'Attaches CSS to a given issue', 'connections' => 'many_to_many', 'required' => 'no', 'is_sortable' => 'yes', 'display_name' => 'Issue CSS')); if ($r_id) { echo '<p>issue_to_css_url allowable relationship successfully created</p>' . "\n"; } else { echo '<p>Unable to create issue_to_css_url allowable relationship. Please create this allowable relationship manually: go into Reason=>Master Admin=>Allowable Relationship Manager=>Add New Allowable Relationship and fill out the form this way:</p>'; echo '<p>Name: issue_to_css_url<br />'; echo 'Description: Attaches CSS to a given issue<br />'; echo 'Relationship A: Issue<br />'; echo 'Relationship B: External URL<br />'; echo 'Connections: Many to Many<br />'; echo 'Directionality: Unidirectional<br />'; echo 'Required: no<br />'; echo 'Is Sortable: yes<br />'; echo 'Display Name: Issue CSS</p>'; } } else { echo '<p>Would have added the issue_to_css_url allowable relationship.</p>' . "\n"; } }
/** * Creates the ownership, borrowing, and archive relationships that are necessary for each Reason type * * @param integer $type_id * @return boolean (success) */ function create_default_rels_for_new_type($type_id) { if(empty($type_id)) { trigger_error('Unable to create default relationships for type id '.$type_id.'; no type_id provided', HIGH); return false; } else $type = new entity($type_id); $values = $type->get_values(); if (!reason_is_entity($type, 'type')) { trigger_error('Unable to create default relationships for type id '.$type_id.'; id does not correspond to a reason type entity.', HIGH); return false; } else $type_unique_name = $type->get_value('unique_name'); if (func_num_args() > 1) { trigger_error('The unique name parameter of create_default_rels_for_new_type is deprecated - the type unique name is determined from the type entity itself'); } if (reason_relationship_names_are_unique()) { $owns_id = create_allowable_relationship(id_of('site'),$type_id,'site_owns_'.$type_unique_name,array('connections'=>'many_to_one','directionality'=>'unidirectional','required'=>'yes','is_sortable'=>'no','type'=>'owns')); $borrows_id = create_allowable_relationship(id_of('site'),$type_id,'site_borrows_'.$type_unique_name,array('connections'=>'many_to_many','directionality'=>'bidirectional','required'=>'no','is_sortable'=>'no','type'=>'borrows')); $archive_id = create_allowable_relationship($type_id,$type_id,$type_unique_name.'_archive',array('connections'=>'many_to_one','directionality'=>'unidirectional','required'=>'no','is_sortable'=>'no','type'=>'archive')); } else { $owns_id = create_allowable_relationship(id_of('site'),$type_id,'owns',array('connections'=>'many_to_one','directionality'=>'unidirectional','required'=>'yes','is_sortable'=>'no')); $borrows_id = create_allowable_relationship(id_of('site'),$type_id,'borrows',array('connections'=>'many_to_many','directionality'=>'bidirectional','required'=>'no','is_sortable'=>'no')); $archive_id = create_allowable_relationship($type_id,$type_id,$type_unique_name.'_archive',array('connections'=>'many_to_one','directionality'=>'unidirectional','required'=>'no','is_sortable'=>'no')); } if($owns_id && $borrows_id && $archive_id) return true; else return false; }
protected function create_social_account_type() { $str = ''; $social_account_type_id = reason_create_entity(id_of('master_admin'), id_of('type'), $this->user_id(), 'Social Account', $this->social_account_type_details); $str .= '<p>Create social account type entity</p>'; create_default_rels_for_new_type($social_account_type_id); create_reason_table('social_account', $this->social_account_type_details['unique_name'], $this->user_id()); $ftet = new FieldToEntityTable('social_account', array('account_type' => array('db_type' => 'tinytext'), 'account_id' => array('db_type' => 'tinytext'), 'account_details' => array('db_type' => 'text'))); $ftet->update_entity_table(); ob_start(); $ftet->report(); $str .= ob_get_contents(); ob_end_clean(); create_allowable_relationship(id_of('site'), id_of('social_account_type'), 'site_to_social_account', $this->site_to_social_account_details); $str .= '<p>Created site to social account relationship.</p>'; create_relationship(id_of('master_admin'), id_of('social_account_type'), relationship_id_of('site_to_type')); return $str; }
protected function create_restricted_group_relationship() { $args = array('description' => 'Used for media access control.', 'connections' => 'one_to_many', 'display_name' => 'Restricted to Group', 'custom_associator' => 'Content Manager'); create_allowable_relationship(id_of('av'), id_of('group_type'), 'av_restricted_to_group', $args); }
foreach ($fields as $key => $value) { $fields[$key] = array('db_type' => $value); } $updater = new FieldToEntityTable('classified_table', $fields); $updater->update_entity_table(); $updater->report(); } echo 'Checking for classified category type... '; if (reason_unique_name_exists('classified_category_type')) { echo 'Classified category type already exists. Proceeding.<br/>'; $classified_category = id_of('classified_category_type'); } else { echo 'Creating classified category type.<br/>'; $classified_category = create_type($admin_site, id_of('type'), $user, 'Classified Category', array('new' => 0, 'plural_name' => 'Classified categories', 'unique_name' => 'classified_category_type')); echo 'Creating allowable relationship with classifieds<br/>'; create_allowable_relationship($classified, $classified_category, 'classified_to_classified_category'); } echo 'Putting entity tables on classified type<br/>'; $rel = relationship_id_of('type_to_table'); foreach (array('classified_table', 'meta', 'chunk', 'dated') as $t) { if (name_exists($t)) { create_relationship($classified, id_of_name($t), $rel); } else { echo "Missing name {$t}!<br/>"; } } echo "Install was successful!<br/>"; } ?> </body></html>
if (!empty($_POST['go']) && ($_POST['go'] == 'run' || $_POST['go'] == 'test')) { if ($_POST['go'] == 'run') { echo '<p>Running updater...</p>' . "\n"; } else { echo '<p>Testing updates...</p>' . "\n"; } $alrel_id = relationship_id_of('page_to_access_group', true, false); if ($alrel_id) { echo '<p>Allowable relationship already exists. No need to run this script.</p>'; } else { $a_side_type_id = id_of('minisite_page'); $b_side_type_id = id_of('group_type'); $name = 'page_to_access_group'; $other_data = array('description' => 'Limits access to a group', 'connections' => 'one_to_many', 'directionality' => 'unidirectional', 'required' => 'no', 'is_sortable' => 'no', 'display_name' => 'Restrict Access', 'description_reverse_direction' => 'Pages that use this group for access restrictions'); if ($_POST['go'] == 'run') { $id = create_allowable_relationship($a_side_type_id, $b_side_type_id, $name, $other_data); if ($id) { echo '<p>Successfully created new allowable relationship (ID ' . $id . '). Relationship info:</p>'; } else { echo '<p>Not able to add new allowable relationship. You should probably try to manually create this relationship, using the info below:</p>'; } } else { echo '<p>Would have created a new allowable relationship. Relationship info:</p>'; } echo '<p><strong>A side type id:</strong> ' . $a_side_type_id . '</p>'; echo '<p><strong>B side type id:</strong> ' . $b_side_type_id . '</p>'; echo '<p><strong>Name:</strong> ' . $name . '</p>'; echo '<p>Other data:</p>'; pray($other_data); } }
if (create_allowable_relationship($issue_type, $image_type, 'issue_to_image', array('connections' => 'one_to_many', 'description' => 'Issue to Image', 'display_name' => 'Associate an image with this issue'))) { echo '<p>Created issue_to_image allowable relationship</p>'; } if (create_allowable_relationship($issue_type, $text_blurb_type, 'issue_to_text_blurb', array('connections' => 'many_to_many', 'description' => 'Issue to Text Blurb', 'display_name' => 'Associate text blurbs with this issue'))) { echo '<p>Created issue_to_text_blurb allowable relationship</p>'; } if ($blog_type_exists && create_allowable_relationship($news_section_type, $blog_type, 'news_section_to_blog', array('connections' => 'one_to_many', 'description' => 'News Section to Publication', 'display_name' => 'Assign this section to a publication'))) { echo '<p>Created news_section_to_blog allowable relationship</p>'; } if (create_allowable_relationship($news_section_type, $image_type, 'news_section_to_image', array('connections' => 'one_to_many', 'description' => 'News Section to Image', 'display_name' => 'Associate image with this news section'))) { echo '<p>Created news_section_to_image allowable relationship</p>'; } if ($blog_type_exists && create_allowable_relationship($blog_type, $news_type, 'blog_to_featured_post', array('connections' => 'many_to_many', 'description' => 'Publication to Featured Post', 'display_name' => 'Assign Featured Posts', 'is_sortable' => 'yes', 'directionality' => 'bidirectional', 'display_name_reverse_direction' => 'Feature on Publiction(s)', 'description_reverse_direction' => 'Featured on Publication(s)'))) { echo '<p>Created blog_to_featured_post allowable relationship</p>'; } if (create_allowable_relationship(id_of('event_type'), $news_type, 'event_to_news', array('description' => 'Event to News / Post', 'connections' => 'many_to_many', 'display_name' => 'Associate with a News Item', 'directionality' => 'bidirectional', 'is_sortable' => 'yes', 'display_name_reverse_direction' => 'Assign to event(s)', 'description_reverse_direction' => 'Events for this news items'))) { echo '<p>Created event_to_news allowable relationship</p>'; } //Update Places a blog on a page relationship to proper format if ($blog_type_exists) { $existing_rel_id = relationship_finder('minisite_page', 'blog_type', 'Places a blog on a page'); if (!empty($existing_rel_id)) { $q = 'UPDATE allowable_relationship SET name="page_to_blog" WHERE ID=' . $existing_rel_id; db_query($q, 'could not update the places a blog on a page relationship'); echo '<p>Renamed "Places a blog on a page" relationship to "page_to_blog"</p>'; } else { echo '<p>The "Places a blog on a page" relationship has already been updated</p>'; } } $news_to_issue_rel = relationship_finder('news', 'issue_type', 'news_to_issue'); $news_to_news_section_rel = relationship_finder('news', 'news_section_type', 'news_to_news_section');
protected function _create_allowable_relationships() { $msg = ''; if (!relationship_id_of('policy_to_access_group', false, false)) { create_allowable_relationship(id_of('policy_type'), id_of('group_type'), 'policy_to_access_group', array('required' => 'no', 'connections' => 'one_to_many', 'display_name' => 'Access Group', 'is_sortable' => 'no', 'custom_associator' => 'Content Manager')); $msg .= '<p>Created the policy_to_access_group allowable relationship</p>' . "\n"; } if (!relationship_id_of('policy_to_relevant_audience', false, false)) { create_allowable_relationship(id_of('policy_type'), id_of('audience_type'), 'policy_to_relevant_audience', array('required' => 'no', 'connections' => 'many_to_many', 'is_sortable' => 'no', 'custom_associator' => 'Content Manager')); $msg .= '<p>Created the policy_to_relevant_audience allowable relationship</p>' . "\n"; } if (!relationship_id_of('policy_to_responsible_department', false, false)) { create_allowable_relationship(id_of('policy_type'), id_of('office_department_type'), 'policy_to_responsible_department', array('required' => 'no', 'connections' => 'one_to_many', 'display_name' => 'Responsible Department', 'is_sortable' => 'no')); $msg .= '<p>Created the policy_to_responsible_department allowable relationship</p>' . "\n"; } if (empty($msg)) { $msg .= '<p>The allowable relationships already exist, so none were created.</p>' . "\n"; } return $msg; }
force_secure_if_available(); $user_netID = check_authentication(); $reason_user_id = get_user_id($user_netID); if (empty($reason_user_id)) { die('valid Reason user required'); } if (!reason_user_has_privs($reason_user_id, 'upgrade')) { die('You must have upgrade privileges to run this script'); } $rel_data = array('connections' => 'many_to_many', 'description' => 'Places a related publication on a page', 'directionality' => 'unidirectional', 'required' => 'no', 'is_sortable' => 'yes', 'display_name' => 'Places a related publication on a page', 'display_name_reverse_direction' => 'Pages where this publication is a related publication', 'description_reverse_direction' => 'Pages where this publication is a related publication'); echo '<h2>Reason Publication Setup</h2>'; if (!isset($_POST['verify'])) { echo '<p>This script creates the page_to_related_publication allowable relationship</p>'; echo_form(); } elseif (isset($_POST['verify']) && $_POST['verify'] == 'Run') { $rel_id = create_allowable_relationship(id_of('minisite_page'), id_of('publication_type'), 'page_to_related_publication', $rel_data); if ($rel_id) { echo '<p>Allowable relationship created</p>'; } else { $test = relationship_find_and_update('minisite_page', 'publication_type', 'page_to_related_publication', $rel_data); if ($test == false) { echo '<p>Allowable relationship did not need updating</p>'; } } } else { echo_form(); } function echo_form() { echo '<form name="doit" method="post" src="' . get_current_url() . '" />'; echo '<p><input type="submit" name="verify" value="Run" /></p>';