function set_publication($pub)
 {
     if (is_numeric($pub)) {
         $id = (int) $pub;
     } elseif (reason_unique_name_exists($pub)) {
         $id = id_of($pub);
     } else {
         die('The publication unique name provided (' . $pub . ') does not exist' . "\n");
     }
     $this->pub = new entity($id);
     if (!$this->pub->get_values()) {
         die('The publication provided does not exist' . "\n");
     }
     if ($this->pub->get_value('type') != id_of('publication_type')) {
         die('The publication provided is not, in fact, a publication' . "\n");
     }
     $this->set_reminder_days($this->pub->get_value('reminder_days'));
     $this->set_reminder_emails($this->pub->get_value('reminder_emails'));
 }
Example #2
0
 /**
  * This is typically the page the module is running on unless parent_unique_name is set.
  *
  * @return object entity parent page
  */
 function get_parent_page()
 {
     if (!isset($this->_parent_page)) {
         if (!empty($this->params['parent_unique_name'])) {
             if (reason_unique_name_exists($this->params['parent_unique_name'])) {
                 $page = new entity(id_of($this->params['parent_unique_name']));
                 if (reason_is_entity($page, 'minisite_page')) {
                     $this->_parent_page = $page;
                 } else {
                     trigger_error('The unique name specified in parent_unique_name (' . $this->params['parent_unique_name'] . ') was ignored - it needs to refer to a minisite page entity.');
                 }
             } else {
                 trigger_error('The unique name specified in parent_unique_name (' . $this->params['parent_unique_name'] . ') was ignored - it does not exist.');
             }
         }
         if (!isset($this->_parent_page)) {
             $this->_parent_page = new entity($this->page_id);
         }
     }
     return $this->_parent_page;
 }
Example #3
0
     echo 'Creating new classified entity table<br/>';
     $table = create_reason_table('classified_table', 'classified_type', $user);
     if ($table) {
         echo 'The table classified_table was created and added to the type classified_type<br />';
     }
     echo 'Populating the entity table<br/>';
     $fields = array('location' => 'tinytext', 'price' => 'decimal(10,2)', 'classified_print_content' => 'text', 'classified_date_available' => 'datetime', 'classified_duration_days' => 'int', 'classified_contact_email' => 'tinytext', 'display_contact_info' => 'boolean');
     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/>";
Example #4
0
 function newsRSS($site_id, $type_id = '')
 {
     $this->special_sites['news'] = reason_unique_name_exists('media_relations') ? id_of('media_relations') : '';
     $this->special_sites['athletics'] = reason_unique_name_exists('athletics') ? id_of('athletics') : '';
     $this->page_type_id = id_of('minisite_page');
     $this->site = new entity($site_id);
     $this->init($site_id, $type_id);
 }
 protected function google_map_type_exists()
 {
     return reason_unique_name_exists('google_map_type', false);
 }
 function process($test = true)
 {
     $ret = '';
     foreach ($this->get_entity_info() as $type_uname => $entities) {
         foreach ($entities as $entity) {
             if (!reason_unique_name_exists($entity['unique_name'])) {
                 if ($test) {
                     $ret .= '<p>Would create ' . $type_uname . ' ' . $entity['name'] . '</p>';
                 } elseif (reason_create_entity(id_of('master_admin'), id_of($type_uname), $this->user_id, $entity['name'], $entity)) {
                     $ret .= '<p>Created ' . $type_uname . ' ' . $entity['name'] . '</p>';
                 } else {
                     $ret .= '<p>ERROR: Unable to create ' . $type_uname . ' ' . $entity['name'] . '</p>';
                 }
             }
         }
     }
     foreach ($this->get_theme_rels() as $theme_uname => $rels) {
         if (reason_unique_name_exists($theme_uname)) {
             $theme = new entity(id_of($theme_uname));
             foreach ($rels as $rel_name => $rel_unames) {
                 $rel_id = relationship_id_of($rel_name);
                 if (empty($rel_id)) {
                     $ret .= '<p>ERROR: unable to create relationships with name ' . $rel_name . ' -- not found</p>';
                     continue;
                 }
                 $rel_entities = $theme->get_left_relationship($rel_name);
                 $rel_unames_in_db = array();
                 foreach ($rel_entities as $rel_entity) {
                     if ($rel_entity->get_value('unique_name')) {
                         $rel_unames_in_db[] = $rel_entity->get_value('unique_name');
                     }
                 }
                 $unrelated = array_diff($rel_unames, $rel_unames_in_db);
                 foreach ($unrelated as $unrelated_uname) {
                     if (!$test) {
                         if (!reason_unique_name_exists($unrelated_uname)) {
                             $ret .= '<p>ERROR: unable to create relationships with unique name ' . $unrelated_uname . ' -- not found</p>';
                             continue;
                         } else {
                             $unrelated_id = id_of($unrelated_uname);
                         }
                     }
                     if ($test) {
                         $ret .= '<p>Would create relationship from ' . $theme_uname . ' to ' . $unrelated_uname . '</p>';
                     } elseif (create_relationship($theme->id(), $unrelated_id, $rel_id)) {
                         $ret .= '<p>Created relationship from ' . $theme_uname . ' to ' . $unrelated_uname . '</p>';
                     } else {
                         $ret .= '<p>ERROR: Unable to create relationship from ' . $theme_uname . ' to ' . $unrelated_uname . '</p>';
                     }
                 }
             }
         } elseif ($test) {
             $ret .= '<p>Would create relationships from ' . $theme_uname . ' to css and templates.</p>';
         } else {
             trigger_error('Unable to create relationship with theme ' . $theme_uname . ' -- it doesn\'t appear to exist!');
             $ret .= '<p>ERROR: Unable to create relationship with theme ' . $theme_uname . ' -- it doesn\'t appear to exist!. Please try running this script again.</p>';
         }
     }
     if (empty($ret)) {
         $ret .= '<p>Upgrade complete; nothing to do</p>';
     }
     return $ret;
 }
Example #7
0
/**
 * Checks whether or not something is an entity.
 *
 * Specifically, this checks if an item is an object and has a method called entity (the entity class constructor). In addition, you
 * can perform extra checks to see if the entity has a type value (any value or a specific value).
 *
 * There are better ways to do this in php 5, but to maintain cross compatibility with php 4 and php 5 instanceof and is_a are not reliable,
 * and so we do a method_exists check to see if the constructor "entity" is defined.
 *
 * Please note this in its default behavior this just checks to see if an item is of class entity - that does not mean it has a type or
 * or exists in the database.
 * 
 * @param object
 * @param mixed of_type - if "true" makes sure the entity has some value for type, if given a unique name, makes sure the entity is of that type.
 * @todo the has_value statements will crash when run on an entity that has been initialized with a string instead of a numeric id - consider fixing this
 * @return boolean
 */
function reason_is_entity($obj, $of_type = false)
{
    $is_entity = is_object($obj) && method_exists($obj, "entity");
    if ($is_entity && $of_type === true) {
        return $obj->has_value('type') ? $obj->get_value('type') : false;
    } elseif ($is_entity && !empty($of_type)) {
        return reason_unique_name_exists($of_type) && $obj->has_value('type') ? $obj->get_value('type') == id_of($of_type) : false;
    }
    return $is_entity;
}
 protected function social_account_type_exists()
 {
     reason_refresh_unique_names();
     // force refresh from the database just in case.
     return reason_unique_name_exists('social_account_type');
 }
Example #9
0
        $args['pub'] = $_GET['pub'];
    } else {
        die('Please provide a publication id or unique name in the "pub" query string parameter' . "\n");
    }
    if (!empty($_GET['days'])) {
        $args['days'] = $_GET['days'];
    } else {
        die('Please provide a days argument' . "\n");
    }
    if (!empty($_GET['emails'])) {
        $args['emails'] = $_GET['emails'];
    }
}
if (is_numeric($args['pub'])) {
    $id = (int) $args['pub'];
} elseif (reason_unique_name_exists($args['pub'])) {
    $id = id_of($args['pub']);
} else {
    die('The publication unique name provided (' . $args['pub'] . ') does not exist' . "\n");
}
$pub = new entity($id);
if (!$pub->get_values()) {
    die('The publication provided does not exist' . "\n");
}
if ($pub->get_value('type') != id_of('publication_type')) {
    die('The publication provided is not, in fact, a publication' . "\n");
}
$days = (int) $args['days'];
if (empty($days)) {
    die('Please provide days as an integer (e.g. 1, 2, 3, or 73)' . "\n");
}
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;
}
Example #11
0
    //?estimate='.$maintenance_estimate );
    die;
}
$f = new AdminPage();
$authenticated = $f->authenticate();
if ($authenticated) {
    $f->init();
    // init returns false if the user cannot be authentication
    if ($f->should_run_api()) {
        $f->run_api();
        exit;
    } else {
        $f->run();
    }
} else {
    if (reason_unique_name_exists('unauthorized_reason_user')) {
        $e = new entity(id_of('unauthorized_reason_user'));
        echo $e->get_value('content');
    } else {
        echo '<p>We\'re sorry, but we do not have any record of you being an authorized Reason user.</p>';
    }
}
$_page_timing_end = getmicrotime();
$page_gen_time = round(1000 * ($_page_timing_end - $_page_timing_start), 0);
echo '<!-- start time: ' . $_page_timing_start . '   end time: ' . $_page_timing_end . '   total time: ' . $page_gen_time . ' ms -->';
reason_log_page_generation_time($page_gen_time);
//echo 'mem usage: '.xdebug_memory_usage().'<br/>';
//xdebug_dump_function_trace();
//xdebug_dump_function_profile(4);
?>
Example #12
0
 function update_whats_new_in_reason_blurb()
 {
     echo '<hr/>';
     if (reason_unique_name_exists('whats_new_in_reason_blurb')) {
         $id = id_of('whats_new_in_reason_blurb');
         $e = new entity($id);
         $name = $e->get_value('name');
         if (trim($name) == 'Welcome to Reason 4 Beta 4') {
             if ($this->mode == 'run') {
                 reason_update_entity($id, $this->reason_user_id, array('name' => 'Welcome to Reason'));
                 echo "<p>Updated the blurb with unique_name 'whats_new_in_reason_blurb' to remove the version number reference.</p>";
             } else {
                 echo "<p>Would update the blurb with unique_name 'whats_new_in_reason_blurb' to remove the version number reference.</p>";
             }
         } else {
             echo "<p>The blurb with unique_name 'whats_new_in_reason_blurb' does not need updating.</p>";
         }
     } else {
         echo "<p>The blurb with unique_name 'whats_new_in_reason_blurb' does not exist in this instance.</p>";
     }
 }
Example #13
0
 function ensure_quote_type_is_using_content_manager()
 {
     if (reason_unique_name_exists('quote_type', false)) {
         $qt_id = id_of('quote_type');
         $qt = new entity($qt_id);
         if ($qt->get_value('custom_content_handler') != 'quote.php') {
             if ($this->mode == 'run') {
                 reason_update_entity($qt_id, $this->reason_user_id, $this->quote_type_details);
                 echo '<p>Updated quote type to use correct content manager.</p>';
             } else {
                 echo '<p>Would update quote type to use correct content manager.</p>';
             }
         } else {
             echo '<p>The quote type is using the correct content manager. No need to update.</p>';
         }
     }
 }
 protected function _create_media_entity($disco)
 {
     // put together the values for the entity
     $name = htmlspecialchars($disco->get_value('media_title'));
     $values = $this->params['default_values'];
     $values['name'] = $name;
     $values['new'] = "0";
     $values['author'] = htmlspecialchars($disco->get_value('name'));
     if ($disco->get_value('class_year')) {
         switch (strlen($disco->get_value('class_year'))) {
             case 4:
                 $values['author'] .= ' \'' . htmlspecialchars(mb_substr($disco->get_value('class_year'), -2));
                 break;
             case 3:
                 $values['author'] .= htmlspecialchars($disco->get_value('class_year'));
                 break;
             case 2:
                 $values['author'] .= ' \'' . htmlspecialchars($disco->get_value('class_year'));
         }
     }
     $values['description'] = htmlspecialchars($disco->get_value('description'));
     $values['keywords'] = $name . ', ' . $values['author'];
     $values['av_type'] = $disco->get_value('av_type');
     $values['integration_library'] = $this->_integration_library;
     $values['original_filename'] = $this->sanitize_filename($this->_filename);
     $values['salt'] = $this->get_salt();
     $values['email_notification'] = true;
     if ($disco->get_value('url')) {
         $values['tmp_file_name'] = $disco->get_value('url');
     } else {
         $values['tmp_file_name'] = basename($disco->get_element('upload_file')->tmp_full_path);
     }
     // create the entity
     $this->_media_work_id = $id = reason_create_entity($this->site_id, id_of('av'), $this->_user_id, $name, $values);
     //$this->set_form_id($id);
     $page_id = $this->page_id;
     if (!empty($this->params['entries_gallery_page'])) {
         if ('parent' == $this->params['entries_gallery_page']) {
             if ($pages =& $this->get_page_nav()) {
                 if ($parent_page_id = $pages->parent($this->page_id)) {
                     $page_id = $parent_page_id;
                 } else {
                     trigger_error('Unable to find parent page. Attaching photos to form page.');
                 }
             } else {
                 trigger_error('Unable to find page tree. Attaching photos to form page.');
             }
         } elseif (reason_unique_name_exists($this->params['entries_gallery_page'])) {
             $page_id = id_of($this->params['entries_gallery_page']);
         } else {
             trigger_error('Unable to find uniquely named page ' . $this->params['entries_gallery_page'] . '. Attaching photos to form page.');
         }
     }
     create_relationship($page_id, $id, relationship_id_of('minisite_page_to_av'));
     // access restriction
     $da = reason_get_default_access();
     if ($this->params['default_group_uname'] && reason_unique_name_exists($this->params['default_group_uname'])) {
         $group_id = id_of($this->params['default_group_uname']);
         create_relationship($id, $group_id, relationship_id_of('av_restricted_to_group'));
     } elseif ($group_id = $da->get($this->site_id, 'av', 'av_restricted_to_group')) {
         create_relationship($id, $group_id, relationship_id_of('av_restricted_to_group'));
     }
     return $id;
 }
Example #15
0
	function _get_no_content_message()
	{
		if(!empty($this->params['no_content_message']))
		{
			$indicator = 'unique_name:';
			if(strpos($this->params['no_content_message'],$indicator) === 0)
			{
				$uname = substr($this->params['no_content_message'],strlen($indicator));
				if(!empty($uname) && reason_unique_name_exists($uname))
				{
					return get_text_blurb_content( $uname );
				}
			}
			else
				return $this->params['no_content_message'];
		}
		return '';
	}
 function create_location_type()
 {
     if (reason_unique_name_exists('location_type') || reason_unique_name_exists('address_type')) {
         echo '<p>This script has probably already been run</p>';
     }
 }
Example #17
0
	/**
	 * Returns an array of id => reason audience entities to exclude based on the exclude_audiences parameter.
	 *
	 * If given a faulty audience unique name, ignore it -- still exclude others
	 * Error triggered if not passed in a string, or if the audiences passed in aren't Reason unique
	 * names.
	 * @return array of id => audience entities, or an empty array
	 */
	function _get_audiences_to_exclude()
	{
		$excluded_audiences = array();
		if(!empty($this->params['exclude_audiences']))
		{
			if(gettype($this->params['exclude_audiences']) != "string")
			{
				trigger_error('The exluded_audiences parameter must be a comma-seperated string of reason unique names. Please 
								check your syntax. Example: \'public_audience, students_audience\'. ');
				return $excluded_audiences;
			}
			$audiences_to_exclude = explode(',', $this->params['exclude_audiences']);
			foreach($audiences_to_exclude as $audience)
			{
				$audience = trim($audience);
				if(reason_unique_name_exists($audience))
				{
					$audience_id = id_of($audience);
					$excluded_audiences[$audience_id] = new entity($audience_id);
				}
				else
				{
					trigger_error('Strings passed in must be Reason unique names. \'' . $audience . '\' is 
									not a Reason unique name. Use: \'public_audience\' for example');
				}
			}
		}
		return $excluded_audiences;
	}
Example #18
0
function admin_user_exists()
{
    reason_include_once('function_libraries/admin_actions.php');
    reason_refresh_unique_names();
    // lets make sure we pull admin_user from the database not the cache.
    return reason_unique_name_exists('admin_user');
}
 protected function _create_media_entity($disco)
 {
     // put together the values for the entity
     $name = htmlspecialchars($disco->get_value('media_title'));
     $values = $this->params['default_values'];
     $values['name'] = $name;
     $values['new'] = "0";
     $values['author'] = htmlspecialchars($disco->get_value('name'));
     if ($disco->get_value('class_year')) {
         switch (strlen($disco->get_value('class_year'))) {
             case 4:
                 $values['author'] .= ' \'' . htmlspecialchars(mb_substr($disco->get_value('class_year'), -2));
                 break;
             case 3:
                 $values['author'] .= htmlspecialchars($disco->get_value('class_year'));
                 break;
             case 2:
                 $values['author'] .= ' \'' . htmlspecialchars($disco->get_value('class_year'));
         }
     }
     $values['description'] = htmlspecialchars($disco->get_value('description'));
     $values['keywords'] = $name . ', ' . $values['author'];
     $values['entry_id'] = $this->_entry->id;
     $values['av_type'] = $disco->get_value('av_type');
     $values['transcoding_status'] = 'converting';
     $values['integration_library'] = 'kaltura';
     $values['tmp_file_name'] = $this->_filename;
     // create the entity
     $this->_media_work_id = $id = reason_create_entity($this->site_id, id_of('av'), $this->_user_id, $name, $values);
     //$this->set_form_id($id);
     $page_id = $this->page_id;
     if (!empty($this->params['entries_gallery_page'])) {
         if (reason_unique_name_exists($this->params['entries_gallery_page'])) {
             $page_id = id_of($this->params['entries_gallery_page']);
         } else {
             trigger_error('Unable to find uniquely named page ' . $this->params['entries_gallery_page'] . '. Attaching photos to form page.');
         }
     }
     create_relationship($page_id, $id, relationship_id_of('minisite_page_to_av'));
     // access restriction
     $da = reason_get_default_access();
     if ($this->params['default_group_uname'] && reason_unique_name_exists($this->params['default_group_uname'])) {
         $group_id = id_of($this->params['default_group_uname']);
         create_relationship($id, $group_id, relationship_id_of('av_restricted_to_group'));
     } elseif ($group_id = $da->get($this->site_id, 'av', 'av_restricted_to_group')) {
         create_relationship($id, $group_id, relationship_id_of('av_restricted_to_group'));
     }
     return $id;
 }
Example #20
0
 function run()
 {
     echo '<div class="oldBrowserAlert">Notice: Reason works with all browsers.  However, it will look and feel quite a lot nicer if you can use it with a modern, standards-based browser such as Internet Explorer 6+, Mozilla 1.5+, Firefox, Netscape 7, Safari, or Opera.</div>' . "\n";
     if (!HTTPS_AVAILABLE && reason_user_has_privs($this->admin_page->user_id, 'upgrade')) {
         echo '<div id="securityWarning">' . "\n";
         echo '<h3>Security Notice</h3>' . "\n";
         echo '<p>This instance of Reason is running <strong>without</strong> https/ssl. This means that credentials and other potentially sensitive information are being sent in the clear. To run Reason with greater security -- and to make this notice go away -- 1) make sure your server is set up to run https and 2) change the setting HTTPS_AVAILABLE to true in settings/package_settings.php.</p>' . "\n";
         echo '</div>' . "\n";
     }
     if ((!defined('REASON_DISABLE_AUTO_UPDATE_CHECK') || !REASON_DISABLE_AUTO_UPDATE_CHECK) && reason_user_has_privs($this->admin_page->user_id, 'upgrade')) {
         reason_include_once('classes/version_check.php');
         $vc = new reasonVersionCheck();
         $resp = $vc->check();
         switch ($resp['code']) {
             case 'version_out_of_date':
                 echo '<div class="versionUpdateNotice">' . htmlspecialchars($resp['message'], ENT_QUOTES);
                 if (!empty($resp['url'])) {
                     echo ' <a href="' . htmlspecialchars($resp['url'], ENT_QUOTES) . '">Link</a>';
                 }
                 echo '</div>' . "\n";
                 break;
             case 'no_version_provided':
             case 'version_not_recognized':
                 trigger_error('Error checking version: ' . $resp['message']);
                 break;
         }
     }
     if (reason_unique_name_exists('whats_new_in_reason_blurb')) {
         $intro = new entity(id_of('whats_new_in_reason_blurb'));
         echo "\n" . '<div id="whatsNew">' . "\n";
         echo '<h3>' . $intro->get_value('name') . '</h3>' . "\n";
         echo '<p><em>Updated ' . prettify_mysql_timestamp($intro->get_value('last_modified'), 'j F Y') . '</em></p>' . "\n";
         echo $intro->get_value('content');
         echo '</div>' . "\n";
     }
 }
Example #21
0
 $home_page_priority = 0.5;
 if (!empty($_GET['home_page_priority'])) {
     $home_page_priority = round((double) $_GET['home_page_priority'], 1);
 }
 $page_type_priorities = array();
 if (!empty($_GET['page_type_priorities'])) {
     $ptp = (array) $_GET['page_type_priorities'];
     foreach ($ptp as $page_type => $priority) {
         $page_type_priorities[$page_type] = round((double) $priority, 1);
     }
 }
 $exclude_sites = array();
 if (!empty($_GET['exclude_sites'])) {
     $sites = (array) $_GET['exclude_sites'];
     foreach ($sites as $site_name) {
         if (reason_unique_name_exists($site_name)) {
             $exclude_sites[] = id_of($site_name);
         }
     }
 }
 // This script could take a while if the
 set_time_limit(3600);
 $es = new entity_selector();
 $es->add_type(id_of('site'));
 $es->add_relation('site_state = "Live"');
 /* Add new relation to indicate to only include sites that are indexable. - AF*/
 //$es->set_num(200);
 if (!empty($exclude_sites)) {
     $es->add_relation('`entity`.`id` NOT IN ("' . implode('","', $exclude_sites) . '")');
 }
 $sites = $es->run_one();
 protected function course_section_type_exists()
 {
     return reason_unique_name_exists('course_section_type');
 }
Example #23
0
        $site_id = id_of($site_uname);
        $site_entity = new entity($site_id);
        if ($site_entity->get_value('type') != id_of('site')) {
            echo 'Site ' . $site_uname . ' not found (Unique name does not belong to a site). Unable to provide access.' . "\n";
        } else {
            if ($user->add_user_to_site($username, $site_id)) {
                echo $username . ' now has access to the site ' . $site_uname . "\n";
            } else {
                echo $username . ' already had access to the site ' . $site_uname . "\n";
            }
        }
    }
}
if (!empty($options['r'])) {
    $role_uname = (string) $options['r'];
    if (!reason_unique_name_exists($role_uname)) {
        echo 'Role ' . $role_uname . ' not found (Bad unique name). Unable to assign role.' . "\n";
    } else {
        $role_id = id_of($role_uname);
        $role_entity = new entity($role_id);
        if ($role_entity->get_value('type') != id_of('user_role')) {
            echo 'Role ' . $role_uname . ' not found (Unique name does not belong to a user role). Unable to assign role.' . "\n";
        } else {
            if (create_relationship($user_entity->id(), $role_id, relationship_id_of('user_to_user_role'), false, true)) {
                echo $username . ' now has the role ' . $role_uname . "\n";
            } else {
                echo $username . ' already had the role ' . $role_uname . "\n";
            }
        }
    }
}