Ejemplo n.º 1
0
 function init()
 {
     $this->type_entity = new entity($this->admin_page->type_id);
     if (!reason_site_can_edit_type($this->admin_page->site_id, $this->admin_page->type_id)) {
         echo 'This site does not have permission to edit ' . $this->type_entity->get_value('plural_name') . '.';
         die;
     }
     if (empty($this->admin_page->id)) {
         if (reason_user_has_privs($this->admin_page->user_id, 'add')) {
             $new_id = create_entity($this->admin_page->site_id, $this->admin_page->type_id, $this->admin_page->user_id, '', array('entity' => array('state' => 'Pending')));
             header('Location: ' . unhtmlentities($this->admin_page->make_link(array('id' => $new_id), true)));
             die;
         } else {
             echo 'You do not have the privileges needed to add a ' . $this->type_entity->get_value('name');
             die;
         }
     }
     $this->entity = new entity($this->admin_page->id);
     if ($this->_cm_ok_to_run()) {
         $this->_do_admin_page_prep();
         $this->disco_item = $this->_build_content_manager();
     }
     $this->head_items->add_javascript(JQUERY_UI_URL, true);
     $this->head_items->add_javascript(JQUERY_URL, true);
     $this->head_items->add_stylesheet(JQUERY_UI_CSS_URL);
     $this->head_items->add_javascript(WEB_JAVASCRIPT_PATH . 'change_detection.js');
 }
Ejemplo n.º 2
0
/**
 * Get the Reason ID for a given username; otherwise create a new user and return created Reason ID
 * @param string $username
 * @param integer $creator_id the ID of the user that is creating the user (if needed)
 * @return integer $user_id
 */
function make_sure_username_is_user($username, $creator_id)
{
	$master_admin_id = id_of('master_admin');
	if(empty($creator_id))
	{
		trigger_error('Creator ID is needed by make_sure_username_is_user (second argument)');
		$creator_id = $master_admin_id;
	}
	if(empty($username))
	{
		trigger_error('Username is needed by make_sure_username_is_user (first argument)', E_USER_ERROR);
		die();
	}
	$es = new entity_selector($master_admin_id);
	$es->add_type(id_of('user'));
	$es->add_relation('entity.name = "'.$username.'"');
	$es->set_num(1);
	$users = $es->run_one();
	if(empty($users))
	{
		$new_user_id = create_entity( 
										$master_admin_id, 
										id_of('user'), 
										$creator_id,
										$username
									);
		return $new_user_id;
	}
	else
	{
		$user = current($users);
		return $user->id();
	}
}
function create_test_request()
{
    $entity = create_entity();
    $mutation = new Google_Service_Datastore_Mutation();
    $mutation->setUpsert([$entity]);
    $req = new Google_Service_Datastore_CommitRequest();
    $req->setMode('NON_TRANSACTIONAL');
    $req->setMutation($mutation);
    return $req;
}
Ejemplo n.º 4
0
function create_request($hashkey, $text)
{
    $entity = create_entity($hashkey, $text);
    $mutation = new Google_Service_Datastore_Mutation();
    $mutation->setInsertAutoId([$entity]);
    // Causes ID to be allocated.
    #  $mutation->setUpsert([$entity]);
    $req = new Google_Service_Datastore_CommitRequest();
    $req->setMode('NON_TRANSACTIONAL');
    $req->setMutation($mutation);
    return $req;
}
Ejemplo n.º 5
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.º 6
0
	/** duplicate_entity( $id, $dup_relationships = true, $maintain_dates = false, $overrides = array() ) {{{
	 *	Duplicates entity with id = $id.
	 *
	 *	Specifically, copies all fields of an entity to a new id.  If dup_relationships
	 *	is true, also copies all relationships, replacing the old id with the new inserted one.
	 *
	 *	@param	$id						ID of entity to duplicate
	 *									OR an entity object to duplicate
	 *	@param	$dup_relationships		Bool that determines whether to duplicate relationships or not
	 *	@param	$maintain_dates			Bool that determines whether to 
	 *	@param	$overrides				array of field => value pairs to override any values for the new entity
	 *	@return							the new, duplicated entity id
	 */
	function duplicate_entity( $id, $dup_relationships = true, $maintain_dates = false, $overrides = array() )
	{
		// get all values and structure from existing object
		if( is_object( $id ) AND get_class( $id ) == 'entity' )
			$e = $id;
		else
			$e = new entity( $id );

		// get the site that owns this entity
		$site = $e->get_owner();
		
		// get the tables used by this type/entity
		$tables = get_entity_tables_by_id( $e->id() );

		//! start of new code (see commented note below)

		$ignored_fields = array( 'id', 'name', 'type', 'last_edited_by' );

		if( !$maintain_dates )
		{
			$ignored_fields[] = 'last_modified';
			$ignored_fields[] = 'creation_date';
		}

		// Don't ignore values set as overrides
		foreach ($ignored_fields as $key => $val)
			if (isset($overrides[$val])) unset ($ignored_fields[$key]);
		
		// convert values of entity to tabled-array structure, make sure to ignore proper fields
		$values = values_to_tables( $tables, array_merge( $e->get_values(), $overrides ), $ignored_fields );
		
		// create new entity record
		$new_entity_id = create_entity(
			$site->id(), 
			$e->get_value('type'), 
			$e->get_value('last_edited_by'), 
			$e->get_value('name'), 
			$values
		);

		// copy relationships
		if( $dup_relationships )
		{
			// make new left relationships
			$left_rels = $e->get_left_relationships();
			foreach( $left_rels AS $rel_type => $rel_obj )
			{
				if( is_int( $rel_type ) )
				{
					foreach( $rel_obj AS $r )
						create_relationship( $new_entity_id, $r->id(), $rel_type );
				}
			}
			// make new right relationships
			$right_rels = $e->get_right_relationships();
			foreach( $right_rels AS $rel_type => $rel_obj )
			{
				if( is_int( $rel_type ) )
				{
					foreach( $rel_obj AS $r )
						create_relationship( $r->id(), $new_entity_id, $rel_type );
				}
			}
		}

		// return the new entity
		return $new_entity_id;
	} // }}}
Ejemplo n.º 7
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'];
     }
 }
    $nes->add_type(id_of('faculty_staff'));
    $reason_fac_staff = $nes->run_one();
    $reason_netids = array();
    $ldap_created = array();
    $reason_id = array();
    foreach ($reason_fac_staff as $f2) {
        $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";
Ejemplo n.º 9
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'];
     }
 }