/**
  * 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.';
     }
 }
Esempio n. 2
0
 function remove_site_to_minisite_template_allowable_relationship()
 {
     echo '<hr/>';
     if (reason_relationship_name_exists('site_to_minisite_template')) {
         $rel_id = relationship_id_of('site_to_minisite_template', false);
         $q = 'DELETE from allowable_relationship WHERE id=' . $rel_id;
         if ($rel_id && $this->mode == 'run') {
             db_query($q);
             echo '<p>Deleted site_to_minisite_template relationship using this query:</p>';
             echo '<p>' . $q . '</p>';
         } elseif ($rel_id && $this->mode == 'test') {
             echo '<p>Would delete site_to_minisite_template relationship using this query:</p>';
             echo '<p>' . $q . '</p>';
         }
     } else {
         echo '<p>The relationship name site_to_minisite_template does not exist in your database</p>';
     }
 }
Esempio n. 3
0
 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";
     }
 }
 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;
 }
Esempio n. 5
0
/**
 * @return boolean whether or not relationship unique names have been implemented in this reason database - call me only once
 */
function reason_relationship_names_are_unique($force_refresh = NULL)
{
    static $rel_names_are_unique;
    if ($force_refresh || !isset($rel_names_are_unique)) {
        $rel_names_are_unique = reason_relationship_name_exists('site_owns_minisite_page', false);
        // lets force a fresh draw
        if ($rel_names_are_unique == false) {
            trigger_error('Reason relationship names not yet unique - please run the 4.1 to 4.2 upgrade script "allowable_relationship_unique_names"');
        }
    }
    return $rel_names_are_unique;
}
Esempio n. 6
0
	/**
	 * Create a new allowable relationship
	 *
	 * Checks to make sure we are not duplicating an existing allowable relationship before creating new one.
	 * 
	 * Checks include: 
	 * 1. the type ids must be the ids of existing reason types
	 * 2. the name must be a nonempty string containing only numbers, letters, and underscores that does not already exist in the allowable relationship table (exception: borrows and owns)
	 * 3. for borrows or owns relationships, the type must not already have an allowable relationship of that type
	 *
	 * @param integer $a_side_type_id The id of the type on the left side of the relationship
	 * @param integer $b_side_type_id The id of the type on the right side of the relationship
	 * @param string $name The unique name of the allowable relationship (or "owns" or "borrows")
	 * @param array $other_data Additional data to be stored in the allowable_relationship table, keyed by field name
	 * @return mixed id of newly created relationship if successful; false if failure
	 *
	 * @todo update to do verification and handling of new "type" field
	 */
	function create_allowable_relationship($a_side_type_id,$b_side_type_id,$name,$other_data = array())
	{
		// validate data
		
		$a_side_type_id = turn_into_int($a_side_type_id);
		$b_side_type_id = turn_into_int($b_side_type_id);
		$name = turn_into_string($name);
		
		if(empty($a_side_type_id))
		{
			trigger_error('$a_side_type_id must be a nonzero integer in create_allowable_relationship()');
			return false;
		}
		$a_ent = new entity($a_side_type_id);
		if(!empty($a_ent))
		{
			if($a_ent->get_value('type') != id_of('type'))
			{
				trigger_error('$a_side_type_id must be the ID of a Reason type entity');
				return false;
			}
		}
		else
		{
			trigger_error('$a_side_type_id is not the ID of a Reason entity');
			return false;
		}
		if(empty($b_side_type_id))
		{
			trigger_error('$b_side_type_id must be a nonzero integer in create_allowable_relationship()');
			return false;
		}
		$b_ent = new entity($b_side_type_id);
		if(!empty($b_ent))
		{
			if($b_ent->get_value('type') != id_of('type'))
			{
				trigger_error('$b_side_type_id must be the ID of a Reason type entity');
				return false;
			}
		}
		else
		{
			trigger_error('$b_side_type_id is not the ID of a Reason entity');
			return false;
		}
		if(empty($name))
		{
			trigger_error('$name must be a string in create_allowable_relationship()');
			return false;
		}
		if( !preg_match( "|^[0-9a-z_]*$|i" , $name ) )
		{
			trigger_error('$name must only contain numbers, letters, and underscores');
			return false;
		}
		
		if (!reason_relationship_names_are_unique())
		{
			$repeatable_names = array('borrows','owns');
			if( !in_array($name,$repeatable_names) && reason_relationship_name_exists($name, false) )
			{
				trigger_error('Unable to create allowable relationship named '.$name.' because there is already an allowable relationship with that name in Reason');
				return false;
			}
			if(in_array($name,$repeatable_names))
			{
				if($a_side_type_id != id_of('site'))
				{
					trigger_error('The a_side_type_id of borrows and owns relationships must be the id of the site type');
					return false;
				}
				// check to see if an owns/borrows relationship already exists for this type
				if ( (($name == 'owns') && get_owns_relationship_id($b_side_type_id)) ||
					 (($name == 'borrows') && get_borrows_relationship_id($b_side_type_id)) )
				{
					trigger_error($name.' relationship already exists between '.$a_side_type_id.' and '.$b_side_type_id.'.');
					return false;
				}
			}
		}
		else
		{
			if (reason_relationship_name_exists($name, false))
			{
				trigger_error('Unable to create allowable relationship named '.$name.' because there is already an allowable relationship with that name in Reason');
				return false;
			}
			if (isset($other_data['type']) && ( ($other_data['type'] == 'owns') || ($other_data['type'] == 'borrows') ) )
			{
				if ($a_side_type_id != id_of('site'))
				{
					trigger_error('The a_side_type_id of borrows and owns relationships must be the id of the site type');
					return false;
				}
				// enforce our naming convention
				$owns_name_should_be = $a_ent->get_value('unique_name') . '_owns_' . $b_ent->get_value('unique_name');
				$borrows_name_should_be = $a_ent->get_value('unique_name') . '_borrows_' . $b_ent->get_value('unique_name');
				if ( ($other_data['type'] == 'owns') && ($name != $owns_name_should_be) )
				{
					trigger_error('A new allowable relationship of type owns must follow the naming convention a_side_unique_name_owns_b_side_entity_unique_name');
					return false;
				}
				elseif ( ($other_data['type'] == 'borrows') && ($name != $borrows_name_should_be) )
				{
					trigger_error('A new allowable relationship of type borrows must follow the naming convention a_side_unique_name_borrows_b_side_entity_unique_name');
					return false;
				}
			}
			if (isset($other_data['type']) && ($other_data['type'] == 'archive'))
			{
				if ($a_side_type_id != $b_side_type_id)
				{
					trigger_error('The a_side_type_id and b_side_type_id of archive relationships must be the same.');
					return false;
				}
				$archive_name_should_be = $a_ent->get_value('unique_name') . '_archive';
				if ($name != $archive_name_should_be)
				{
					trigger_error('A new allowable relationship of type archive must follow the naming convention type_unique_name_archive');
					return false;
				}
			}
		}
		
		// do the creation of the allowable relationship
		
		$default_values = array(
								'directionality'=>'unidirectional',
								'is_sortable'=>'no',
								'connections'=>'many_to_many',
								'required'=>'no',
		);
		if (reason_relationship_names_are_unique()) $default_values['type'] = 'association';
		$values = array_merge($default_values,$other_data);
		$values['relationship_a'] = $a_side_type_id;
		$values['relationship_b'] = $b_side_type_id;
		$values['name'] = $name;
		
		$sqler = new SQLER();
		if($sqler->insert('allowable_relationship',$values))
		{
			$insert_id = mysql_insert_id();
			reason_refresh_relationship_names();
			return $insert_id;
		}
		else
		{
			return false;
		}
	}
function verify_relationship($left_side_entity_type, $right_side_entity_type, $relationship_type)
{
    $pass = true;
    if (!reason_relationship_name_exists($relationship_type)) {
        trigger_error('The relationship name ' . $relationship_type . ' does not exist!');
        $pass = false;
    }
    if (!reason_unique_name_exists($left_side_entity_type)) {
        trigger_error('The left side type with unique name ' . $relationship_type . ' does not exist!');
        $pass = false;
    }
    if (!reason_unique_name_exists($right_side_entity_type)) {
        trigger_error('The right side type with unique name ' . $relationship_type . ' does not exist!');
        $pass = false;
    }
    $r_id = relationship_id_of($relationship_type);
    $q = 'SELECT is_sortable FROM allowable_relationship WHERE id=' . $r_id;
    $results = db_query($q);
    $result = mysql_fetch_assoc($results);
    if ($result['is_sortable'] == 'yes') {
        echo '<p>The relationship is already sortable - this script has probably been run already</p>';
        $pass = false;
    }
    return $pass;
}
 function name_uniqueness_check()
 {
     if (reason_relationship_name_exists($this->get_value('name')) && relationship_id_of($this->get_value('name')) != $this->get_value('id')) {
         return false;
     } else {
         return true;
     }
 }