Ejemplo n.º 1
0
	/** reason_update_entity( $id, $user_id, $updates = array(), $archive = true ) {{{
	 *	Updates entity with id = $id with the values of the array $values
	 *
	 *	@param	integer	$id	ID of entity to update
	 *	@param 	integer	$user_id	Reason ID of user making changes
	 *	@param	array	$updates	simple array of key-val pairs (no tables needed)
	 *	@param	boolean	$archive	boolean that determines whether this update will be archived
	 *	@returns	boolean	true => entity has changed,  false => entity has not changed
	 */
	function reason_update_entity( $id, $user_id, $updates = array(), $archive = true)
	{
		if(empty($id))
		{
			trigger_error('reason_update_entity() needs an id to function properly');
			return false;
		}
		elseif(empty($user_id))
		{
			trigger_error('reason_update_entity() needs a user_id to function properly');
			return false;
		}
		else
		{
			$e = new entity($id);
			if($e->get_value('type'))
			{
				$tables = get_entity_tables_by_type($e->get_value('type'));
				$prepped_values = values_to_tables($tables, $updates);
				return update_entity( $id, $user_id, $prepped_values, $archive);
			}
			else
			{
				trigger_error('id passed not an entity id or doesn\'t have a type value');
				return false;
			}
		}
	}
Ejemplo n.º 2
0
 /**
  * Save an entity.
  *
  * @return bool/int
  * @throws IOException
  */
 public function save()
 {
     $guid = (int) $this->guid;
     if ($guid > 0) {
         cache_entity($this);
         return update_entity($this->get('guid'), $this->get('owner_guid'), $this->get('access_id'), $this->get('container_guid'), $this->get('time_created'));
     } else {
         // Create a new entity (nb: using attribute array directly
         // 'cos set function does something special!)
         $this->attributes['guid'] = create_entity($this->attributes['type'], $this->attributes['subtype'], $this->attributes['owner_guid'], $this->attributes['access_id'], $this->attributes['site_guid'], $this->attributes['container_guid']);
         if (!$this->attributes['guid']) {
             throw new IOException(elgg_echo('IOException:BaseEntitySaveFailed'));
         }
         // Save any unsaved metadata
         // @todo How to capture extra information (access id etc)
         if (sizeof($this->temp_metadata) > 0) {
             foreach ($this->temp_metadata as $name => $value) {
                 $this->{$name} = $value;
                 unset($this->temp_metadata[$name]);
             }
         }
         // Save any unsaved annotations.
         if (sizeof($this->temp_annotations) > 0) {
             foreach ($this->temp_annotations as $name => $value) {
                 $this->annotate($name, $value);
                 unset($this->temp_annotations[$name]);
             }
         }
         // Save any unsaved private settings.
         if (sizeof($this->temp_private_settings) > 0) {
             foreach ($this->temp_private_settings as $name => $value) {
                 $this->setPrivateSetting($name, $value);
                 unset($this->temp_private_settings[$name]);
             }
         }
         // set the subtype to id now rather than a string
         $this->attributes['subtype'] = get_subtype_id($this->attributes['type'], $this->attributes['subtype']);
         // Cache object handle
         if ($this->attributes['guid']) {
             cache_entity($this);
         }
         return $this->attributes['guid'];
     }
 }
Ejemplo n.º 3
0
 /**
  * Save generic attributes to the entities table.
  */
 public function save()
 {
     $guid = (int) $this->guid;
     if ($guid > 0) {
         cache_entity($this);
         return update_entity($this->get('guid'), $this->get('owner_guid'), $this->get('access_id'), $this->get('container_guid'));
     } else {
         $this->attributes['guid'] = create_entity($this->attributes['type'], $this->attributes['subtype'], $this->attributes['owner_guid'], $this->attributes['access_id'], $this->attributes['site_guid'], $this->attributes['container_guid']);
         // Create a new entity (nb: using attribute array directly 'cos set function does something special!)
         if (!$this->attributes['guid']) {
             throw new IOException(elgg_echo('IOException:BaseEntitySaveFailed'));
         }
         // Save any unsaved metadata TODO: How to capture extra information (access id etc)
         if (sizeof($this->temp_metadata) > 0) {
             foreach ($this->temp_metadata as $name => $value) {
                 $this->{$name} = $value;
                 unset($this->temp_metadata[$name]);
             }
         }
         // Save any unsaved annotations metadata. TODO: How to capture extra information (access id etc)
         if (sizeof($this->temp_annotations) > 0) {
             foreach ($this->temp_annotations as $name => $value) {
                 $this->annotate($name, $value);
                 unset($this->temp_annotations[$name]);
             }
         }
         // Cache object handle
         if ($this->attributes['guid']) {
             cache_entity($this);
         }
         return $this->attributes['guid'];
     }
 }
Ejemplo n.º 4
0
} else {
    foreach ($old_templates as $entity) {
        if ($entity->get_value('name') == 'tableless2') {
            $new_name = 'carleton_default';
        }
        if ($entity->get_value('name') == 'tableless2_unbranded') {
            $new_name = 'default';
        }
        if ($entity->get_value('name') == 'unbranded') {
            $new_name = 'tables';
        }
        if ($entity->get_value('name') == 'default') {
            $new_name = 'carleton_tables';
        }
        echo 'update_entity( ' . $entity->get_value('id') . ', ' . $user_id . ', array( \'entity\' => array(\'name\' => \'' . $new_name . '\')));';
        update_entity($entity->get_value('id'), $user_id, array('entity' => array('name' => $new_name)));
    }
}
$es = new entity_selector();
$es->add_relation('entity.name = "external_css"');
$es->set_num(1);
$tables = $es->run_one(id_of('content_table'));
if (empty($tables)) {
    echo 'no "external_css" content table entity exists<br />';
    $table_id = create_reason_table('external_css', 'css', $current_user);
    if (!empty($table_id)) {
        echo 'Created external_css table for the css type<br />';
        reason_include_once('classes/field_to_entity_table_class.php');
        reason_include_once('classes/amputee_fixer.php');
        $fields = array('css_relative_to_reason_http_base' => array('db_type' => "enum('true','false')"));
        $updater = new FieldToEntityTable('external_css', $fields);
        $reason_netids[] = $f2->get_value('name');
        if ($f2->get_value('ldap_created') == 'yes') {
            $ldap_created[] = $f2->get_value('name');
            $reason_id[$f2->get_value('name')] = $f2->id();
        }
    }
    $diff = array_diff($netids, $reason_netids);
    foreach ($diff as $new_person) {
        $report_section .= "--------Added {$new_person}\n";
        create_entity($site->id(), id_of('faculty_staff'), $creator, $new_person, array('faculty_staff' => array('ldap_created' => 'yes'), 'entity' => array('new' => 0)));
        $did_something = true;
    }
    //delete ldap created entries
    $diff = array_diff($ldap_created, $netids);
    foreach ($diff as $old_person) {
        update_entity($reason_id[$old_person], id_of('ldap'), array('entity' => array('state' => 'Deleted'), 'faculty_staff' => array('ldap_created' => 'no')), false);
        $report_section .= "---------Deleted {$old_person}\n";
        $did_something = true;
    }
    $report_section .= "\n";
    if ($did_something) {
        $report .= $report_section;
    }
}
$report_foot = "\n\n------------- done -------------\n";
if (!empty($report)) {
    $report = $report_head . $report . $report_foot;
    //mail(ADMIN_NOTIFICATIONS_EMAIL_ADDRESSES,'Reason fac/staff sync report', $report);
    echo $report;
} else {
    echo 'No synchronization actions needed';
Ejemplo n.º 6
0
if (!isset($_POST['verify'])) {
    echo '<p>This script creates a number of fields in the user entity table, and sets the user type to use the user content previewer.';
    echo 'Running this script changes the reason database so that the Reason user type can be used for authentication purposes.</p>';
}
if (isset($_POST['verify']) && $_POST['verify'] == 'Run the Script') {
    // Use the field_to_entity_table_class to add needed fields to 'user' entity table
    $fields = array('user_surname' => array('db_type' => 'tinytext'), 'user_given_name' => array('db_type' => 'tinytext'), 'user_email' => array('db_type' => 'tinytext'), 'user_phone' => array('db_type' => 'tinytext'), 'user_password_hash' => array('db_type' => 'tinytext'), 'user_authoritative_source' => array('db_type' => "enum('reason','external')"));
    $updater = new FieldToEntityTable('user', $fields);
    $updater->update_entity_table();
    $updater->report();
    // Set the custom_previewer value for the User type to User
    $user_type_entity = new entity(id_of('user'));
    $previewer = $user_type_entity->get_value('custom_previewer');
    if ($previewer != "user.php") {
        $update_array = array('type' => array('custom_previewer' => 'user.php'));
        $update = update_entity($user_type_entity->id(), $user_id, $update_array, false);
        if ($update) {
            echo '<h2>Updated user content previewer to user.php</h2>';
        }
    } else {
        echo '<h3>User content previewer already set to user.php</h3>';
    }
    $group_fields = array('ldap_group_filter' => array('db_type' => 'text'), 'ldap_group_member_fields' => array('db_type' => 'tinytext'), 'group_has_members' => array('db_type' => 'enum(\'true\',\'false\')'));
    $updater = new FieldToEntityTable('user_group', $group_fields);
    $updater->update_entity_table();
    $updater->report();
    // check to see if field is still in db
    $results = db_query('DESCRIBE user_group');
    $field_exists = false;
    while ($row = mysql_fetch_array($results)) {
        if ($row['Field'] == 'course_identifier_strings') {
Ejemplo n.º 7
0
 /**
  * Save an entity.
  *
  * @return bool|int
  * @throws IOException
  */
 public function save()
 {
     $guid = $this->getGUID();
     if ($guid > 0) {
         // See #5600. This ensures the lower level can_edit_entity() check will use a
         // fresh entity from the DB so it sees the persisted owner_guid
         _elgg_disable_caching_for_entity($guid);
         $ret = update_entity($guid, $this->get('owner_guid'), $this->get('access_id'), $this->get('container_guid'), $this->get('time_created'));
         _elgg_enable_caching_for_entity($guid);
         _elgg_cache_entity($this);
         return $ret;
     } else {
         // Create a new entity (nb: using attribute array directly
         // 'cos set function does something special!)
         $this->attributes['guid'] = create_entity($this->attributes['type'], $this->attributes['subtype'], $this->attributes['owner_guid'], $this->attributes['access_id'], $this->attributes['site_guid'], $this->attributes['container_guid']);
         if (!$this->attributes['guid']) {
             throw new IOException(elgg_echo('IOException:BaseEntitySaveFailed'));
         }
         // Save any unsaved metadata
         // @todo How to capture extra information (access id etc)
         if (sizeof($this->temp_metadata) > 0) {
             foreach ($this->temp_metadata as $name => $value) {
                 $this->{$name} = $value;
                 unset($this->temp_metadata[$name]);
             }
         }
         // Save any unsaved annotations.
         if (sizeof($this->temp_annotations) > 0) {
             foreach ($this->temp_annotations as $name => $value) {
                 $this->annotate($name, $value);
                 unset($this->temp_annotations[$name]);
             }
         }
         // Save any unsaved private settings.
         if (sizeof($this->temp_private_settings) > 0) {
             foreach ($this->temp_private_settings as $name => $value) {
                 $this->setPrivateSetting($name, $value);
                 unset($this->temp_private_settings[$name]);
             }
         }
         // set the subtype to id now rather than a string
         $this->attributes['subtype'] = get_subtype_id($this->attributes['type'], $this->attributes['subtype']);
         _elgg_cache_entity($this);
         return $this->attributes['guid'];
     }
 }