예제 #1
0
	function attach_template($template_id)
	{
		if($this->test_mode)
		{
			$this->report .= '<p>Would have attached template id '.$template_id.'</p>';
			return true;
		}
		if(!empty($this->id))
		{
			$old_template_id = $this->get_template_id();
			if($old_template_id != $template_id)
			{
				if($old_template_id)
				{
					delete_relationships(
array( 'entity_a' => $this->id , 'entity_b' => $old_template_id , 'type' => relationship_id_of('theme_to_minisite_template') ) );
				}
				return(create_relationship( $this->id, $template_id, relationship_id_of('theme_to_minisite_template')));
			}
			else
			{
				return true;
			}
		}
		else
		{
			trigger_error('could not add template, as theme does not yet have an id');
			return false;
		}
	}
 /**
  * Run the upgrader
  *
  * @return string HTML report
  */
 public function run()
 {
     $results = $this->get_entities_to_delete($this->get_parameter_array());
     $to_return = '';
     foreach ($results as $res_id => $result) {
         delete_relationships(array('entity_a' => id_of('master_admin'), 'entity_b' => $result->id(), 'type' => relationship_id_of('site_to_admin_link')));
         $to_return .= '<p>Removed ' . $result->get_value('name') . ' from the admin links on master admin.</p>';
     }
     if ($to_return == '') {
         $to_return = '<p>This updater has already been run.</p>';
     } else {
         $to_return .= '<p><strong>Note:</strong> These administrative functions will still be available in the Admin Tools interface.</p>';
     }
     return $to_return;
 }
예제 #3
0
 /**
  * Lists the current and available themes (if appropriate to do so) otherwise, changes the theme
  * if the user has selected a new one
  * 
  * @return void
  */
 function run()
 {
     if (!empty($this->admin_page->request['chosen_theme'])) {
         if ($this->self_change) {
             //create a relationship of type site_has_had_theme (if needed)
             $oldies = $this->get_previously_selected_themes();
             $site_type_themes = $this->get_site_type_themes(false);
             $e = $this->get_current_theme();
             if ($e) {
                 if (!entity_in_array($oldies, $e->id()) and !entity_in_array($site_type_themes, $e->id())) {
                     create_relationship($this->admin_page->site_id, $e->id(), relationship_id_of('site_has_had_theme'));
                 }
             }
             //do relationship adding/deleting
             delete_relationships(array('entity_a' => $this->admin_page->site_id, 'type' => relationship_id_of('site_to_theme')));
             create_relationship($this->admin_page->site_id, $this->admin_page->request['chosen_theme'], relationship_id_of('site_to_theme'));
         }
         $link = $this->admin_page->make_link(array('cur_module' => 'ChooseTheme', 'chosen_theme' => ''));
         header('Location: ' . unhtmlentities($link));
     } else {
         $this->list_available_themes();
     }
 }
예제 #4
0
 function _process_relationship_element($name, $info)
 {
     $values = $this->get_value($name);
     if (!is_array($values)) {
         $values = array($values);
     }
     foreach ($info['options'] as $id) {
         if (in_array($id, $values)) {
             if (!in_array($id, $info['related_at_prep'])) {
                 // this neeeds a little more mojo to be site context aware
                 if ($info['direction'] == 'right') {
                     create_relationship($this->get_value('id'), $id, $info['rel_id']);
                 } else {
                     // if $id is not owned by current site, add site id to relationship
                     create_relationship($id, $this->get_value('id'), $info['rel_id'], array('site' => $this->_get_rel_site_value($id)));
                 }
             }
         } else {
             if (in_array($id, $info['related_at_prep'])) {
                 if ($info['direction'] == 'right') {
                     $conditions = array('entity_a' => $this->get_value('id'), 'entity_b' => $id, 'type' => $info['rel_id'], 'site' => 0);
                 } else {
                     $conditions = array('entity_a' => $id, 'entity_b' => $this->get_value('id'), 'type' => $info['rel_id'], 'site' => $this->_get_rel_site_value($id));
                 }
                 delete_relationships($conditions);
             }
         }
     }
 }
예제 #5
0
	/**
	 * Move all the fields of one table into another table for a specific type
	 *
	 * This method is for denormalizing Reason tables. For example, a type may use a common table
	 * like meta, datetime, or chunk. For performance reasons, it can be desirable to collapse
	 * these tables into a single table just for that type. This method will do that.
	 * 
	 * @param integer $type The ID of the type whose fields we are moving
	 * @param string $source_table The name of the table we are moving fields FROM
	 * @param string $destination_table The name of the table we are moving fields TO
	 * @param integer $user_id The Reason ID of the user who is doing this move
	 * @return boolean Success
	 *
	 * @todo Add limit to ensure fields are only created that don't already exist
	 */
	function reason_move_table_fields($type, $source_table, $destination_table, $user_id)
	{
		// Sanity checks
		
		if(empty($type))
		{
			trigger_error('No type provided in reason_move_table_fields()');
			return false;
		}
		
		if(empty($source_table))
		{
			trigger_error('No source table provided in reason_move_table_fields()');
			return false;
		}
		
		if(!is_string($source_table))
		{
			trigger_error('Source table provided not a string in reason_move_table_fields()');
			return false;
		}
		
		if(empty($destination_table))
		{
			trigger_error('No destination table provided in reason_move_table_fields()');
			return false;
		}
		
		if(!is_string($destination_table))
		{
			trigger_error('Destination table provided not a string in reason_move_table_fields()');
			return false;
		}
		
		if('entity' == $source_table || 'entity' == $destination_table)
		{
			trigger_error('reason_move_table_fields() cannot move fields into or out of the entity table.');
			return false;
		}
		
		if(is_object($type))
		{
			$type_id = $type->id();
		}
		elseif(is_numeric($type))
		{
			$type_id = (integer) $type;
		}
		else
		{
			$type_id = id_of($type);
		}
		
		if(empty($type_id))
		{
			trigger_error('Invalid type specified in reason_move_table_fields().');
			return false;
		}
		
		if(is_object($type))
			$type_entity = $type;
		else
			$type_entity = new entity($type_id);
		
		$type_vals = $type_entity->get_values();
		if(empty($type_vals))
		{
			trigger_error('Type specified (id '.$type_id.') is not a Reason entity in reason_move_table_fields().');
			return false;
		}
		if($type_entity->get_value('type') != id_of('type'))
		{
			trigger_error('Type specified (id '.$type_id.') is not a Type entity in reason_move_table_fields().');
			return false;
		}
		if($type_entity->get_value('state') != 'Live')
		{
			trigger_error('Type specified (id '.$type_id.') is not a live entity in reason_move_table_fields().');
			return false;
		}
		
		if(empty($user_id))
		{
			trigger_error('No user id specified in reason_move_table_fields().');
			return false;
		}
		$user = new entity($user_id);
		if(!$user->get_values() || $user->get_value('type') != id_of('user'))
		{
			trigger_error('Invalid user ID specified in reason_move_table_fields().');
			return false;
		}
		
		// check for table existence
		$es = new entity_selector();
		$es->add_type(id_of('content_table'));
		$es->add_relation('`name` = "'.addslashes($source_table).'"');
		$source_table_result = $es->run_one();
		if(empty($source_table_result))
		{
			trigger_error('Source table "'.$source_table.'" does not exist in reason_move_table_fields()');
			return false;
		}
		
		$es = new entity_selector();
		$es->add_type(id_of('content_table'));
		$es->add_relation('`name` = "'.addslashes($destination_table).'"');
		$destination_table_result = $es->run_one();
		if(empty($destination_table_result))
		{
			trigger_error('Destination table "'.$destination_table.'" does not exist in reason_move_table_fields()');
			return false;
		}
		
		$source_table_entity = current($source_table_result);
		$destination_table_entity = current($destination_table_result);
		
		// ensure type uses both tables
		
		$type_tables = get_entity_tables_by_type( $type_id );
		
		if(!in_array($source_table, $type_tables))
		{
			trigger_error('Source table "'.$source_table.'" not part of the type in reason_move_table_fields()');
			return false;
		}
		
		if(!in_array($destination_table, $type_tables))
		{
			trigger_error('Destination table "'.$destination_table.'" not part of the type in reason_move_table_fields()');
			return false;
		}
		
		$es = new entity_selector();
		$es->add_type(id_of('type'));
		$es->add_left_relationship($destination_table_entity->id(),relationship_id_of('type_to_table'));
		$es->add_relation('`entity`.`id` != "'.addslashes($type_id).'"');
		$other_types = $es->run_one();
		
		if(!empty($other_types))
		{
			trigger_error(count($other_types).' other type(s) share the destination table with the type specified in reason_move_table_fields(). reason_move_table_fields() can only move fields into single-type tables.');
			return false;
		}
		
		// get the fields in the old table
		$es = new entity_selector();
		$es->add_type(id_of('field'));
		$es->add_left_relationship($source_table_entity->id(), relationship_id_of('field_to_entity_table'));
		$source_table_fields = $es->run_one();
		
		if(empty($source_table_fields))
		{
			trigger_error('Source table '.$source_table.' does not appear to have any fields associated with it in Reason. Unable to move its content in reason_move_table_fields()');
		}
		
		$q = 'DESCRIBE `'.addslashes($destination_table).'`';
		$handle = db_query( $q, 'Unable to describe destination table in reason_move_table_fields()' );
		$raw_dest_cols = array();
		while($row = mysql_fetch_assoc($handle))
		{
			$raw_dest_cols[] = $row['Field'];
		}
		
		
		foreach($source_table_fields as $k=>$field)
		{
			if(in_array($field->get_value('name'),$raw_dest_cols))
			{
				trigger_error($field->get_value('name').' field is already in destination table. Unable to accomplish reason_move_table_fields().');
				return false;
			}
			$tmp_field_name = $field->get_value('name').'_move_tmp';
			if(in_array($tmp_field_name,$raw_dest_cols))
			{
				trigger_error($tmp_field_name.' field already in destination table. There appears to have been an error in a previous attempt to run reason_move_table_fields(). Please drop this column in MySQL and try again.');
				return false;
			}
			$source_table_fields[$k]->set_value('_field_move_temp_name',$field->get_value('name').'_move_tmp');
		}
		
		// Done with sanity checks
		
		
		// map old to temp field names & create new fields
		$query_parts = array();
		foreach($source_table_fields as $k=>$field)
		{
			$source_table_fields[$k]->set_value('_field_move_temp_name',$field->get_value('name').'_move_tmp');
			$q = 'ALTER TABLE `'.addslashes($destination_table).'` ADD '.addslashes( $field->get_value('_field_move_temp_name') ).' '. $field->get_value('db_type');
			db_query( $q, 'Unable to create new field '.$field->get_value('_field_move_temp_name').' in reason_move_table_fields()' );
			$values = array();
			foreach($field->get_values() as $f=>$v)
			{
				if($f != 'name' && $f != 'id' && strpos($f,'_') !== 0)
				{
					$values[$f] = $v;
				}
			}
			$id = reason_create_entity( id_of('master_admin'), id_of('field'), $user_id, $field->get_value('_field_move_temp_name'), $values);
			$source_table_fields[$k]->set_value('_new_field_id',$id);
			$query_parts[] = '`'.addslashes($destination_table).'`.`'.addslashes($field->get_value('_field_move_temp_name')).'` = `'.addslashes($source_table).'`.`'.addslashes($field->get_value('name')).'`';
		}
		
		// copy content of old fields to new fields
		
		
		$q = 'UPDATE `'.addslashes($destination_table).'`, `'.addslashes($source_table).'`, `entity` SET '.implode(' , ',$query_parts).' WHERE `'.addslashes($destination_table).'`.`id` = `'.addslashes($source_table).'`.`id` AND `'.addslashes($destination_table).'`.`id` = `entity`.`id` AND `entity`.`type` = "'.addslashes($type_id).'";';
		
		db_query($q,'Attempt to move data between fields');
		
		
		// zap source table's type-to-table relationship for this type
		
		$conditions = array(
			'entity_a' => $type_id,
			'entity_b' => $source_table_entity->id(),
			'type' => relationship_id_of('type_to_table'),
		);
		
		delete_relationships( $conditions );
		
		// create new field-to-table relationship for new fields and update field names in new table -- remove temp flag
		
		foreach($source_table_fields as $field)
		{
			create_relationship( $field->get_value('_new_field_id'), $destination_table_entity->id(), relationship_id_of(	'field_to_entity_table' ) );
			$q = 'ALTER TABLE `'.addslashes($destination_table).'` CHANGE '.addslashes($field->get_value('_field_move_temp_name')).' '.addslashes( $field->get_value('name') ).' '.$field->get_value('db_type') ;
			db_query( $q, 'Unable to change field name of '.$field->get_value('_field_move_temp_name').' in reason_move_table_fields()' );
			reason_update_entity( $field->get_value('_new_field_id'), $user_id, array('name' => $field->get_value('name') ), false );
		}
		
		// delete the rows from the source table
		
		$q = 'DELETE `'.addslashes($source_table).'` FROM `'.addslashes($source_table).'`, `entity` WHERE `'.addslashes($source_table).'`.`id` = `entity`.`id` AND `entity`.`type` = "'.addslashes($type_id).'"';
		
		db_query($q,'Attempt to delete rows from '.$source_table.' in reason_move_table_fields()');
		
		get_entity_tables_by_id( $type_id, false );
		
		return true;
			
	}
 /**
  * This callback generates the thumbnail image for the video.  It also updates some metadata 
  * such as duration for the entity.
  */
 public function _process_callback()
 {
     $username = reason_check_authentication();
     reason_update_entity($this->manager->get_value('id'), get_user_id($username), array('media_publication_datetime' => date('Y-m-d H:i:s')), false);
     if ($this->manager->get_value('vimeo_url') && $this->manager->get_value('entry_id') != $this->original_entry_id) {
         // create image file in the vimeo temp directory
         $tmp_path = VimeoShim::get_temp_dir() . 'tmp_thumbnail_' . $this->manager->get_value('id');
         $f = fopen($tmp_path, 'w');
         $image_url = $this->shim->get_thumbnail($this->manager->get_value('entry_id'));
         $contents = get_reason_url_contents($image_url);
         fwrite($f, $contents);
         fclose($f);
         // Create a reason entity out of the temp image file
         if (!empty($tmp_path) and file_exists($tmp_path) && $username) {
             if ($id = $this->create_image_entity($username)) {
                 $im = new ImageManager();
                 $im->thumbnail_width = REASON_STANDARD_MAX_THUMBNAIL_WIDTH;
                 $im->thumbnail_height = REASON_STANDARD_MAX_THUMBNAIL_HEIGHT;
                 $im->max_width = REASON_STANDARD_MAX_IMAGE_WIDTH;
                 $im->max_height = REASON_STANDARD_MAX_IMAGE_HEIGHT;
                 $im->load_by_type(id_of('image'), $id, get_user_id($username));
                 $im->handle_standard_image($id, $tmp_path);
                 $im->create_default_thumbnail($id);
                 $values = array();
                 foreach ($im->get_element_names() as $element_name) {
                     $values[$element_name] = $im->get_value($element_name);
                 }
                 reason_update_entity($id, get_user_id($username), $values, false);
                 // Remove any existing association with an image and replace it with this new one
                 delete_relationships(array('entity_a' => $this->manager->get_value('id'), 'type' => relationship_id_of('av_to_primary_image')));
                 create_relationship($this->manager->get_value('id'), $id, relationship_id_of('av_to_primary_image'));
             }
         }
         // update the duration field of the media work.
         $data_obj = $this->shim->get_video_data($this->manager->get_value('entry_id'));
         if ($data_obj) {
             reason_update_entity($this->manager->get_value('id'), get_user_id($username), array('media_duration' => format_seconds_as_human_readable(intval($data_obj->duration))), false);
         }
     }
 }
예제 #7
0
		function _process_policy_metadata(&$disco)
		{
			$values['approvals'] = tidy($disco->get_value('approvals'));
			$values['last_revised_date'] = tidy($disco->get_value('last_revised_date'));
			$values['last_reviewed_date'] = carl_date('Y-m-d');
			$values['keywords'] = tidy($disco->get_value('keywords'));

			foreach ($this->all_audiences as $audience)
			{	
				// if the audience is checked
				if (in_array($this->audience_opts[$audience->get_value('name')], $disco->get_value('audiences')))
				{
					if (!in_array($audience, $this->related_audiences))
					{
						create_relationship($this->edit_policy->id(), $audience->id(), relationship_id_of('policy_to_relevant_audience'));
					}
				}
				// if the audience was unchecked by the user
				elseif (in_array($audience, $this->related_audiences))
				{
					$conditions = array(
						'entity_a'=> $this->edit_policy->id(),
						'entity_b'=> $audience->id(),
						'type'=> relationship_id_of('policy_to_relevant_audience'),
					);
					delete_relationships($conditions);
				}
			}
			$archive = ($disco->get_chosen_action() == 'save_and_finish') ? true : false;
			$succes = reason_update_entity( $this->request['policy_id'], $this->get_update_entity_user_id(), $values, $archive );
		}
예제 #8
0
    zap_field('blog', 'pagination_state', $reason_user_id);
    zap_field('blog', 'enable_front_end_posting', $reason_user_id);
    $pub_type_id = id_of('publication_type');
    if ($pub_type_id) {
        //check if type is related to commenting_settings entity table and if so, kill the rel
        $es = new entity_selector();
        $es->add_type(id_of('content_table'));
        $es->add_relation('entity.name = "commenting_settings"');
        $es->add_right_relationship($pub_type_id, relationship_id_of('type_to_table'));
        $es->set_num(1);
        $es->limit_tables();
        $es->limit_fields();
        $result = $es->run_one();
        if (!empty($result)) {
            $table = current($result);
            delete_relationships(array('entity_a' => $pub_type_id, 'entity_b' => $table->id(), 'type' => relationship_id_of('type_to_table')));
            // grab all publication entities
            $es2 = new entity_selector();
            $es2->add_type(id_of('publication_type'));
            $es2->limit_tables();
            $es2->limit_fields();
            $result2 = $es2->run_one();
            $ids = implode(",", array_keys($result2));
            $q = "DELETE from commenting_settings WHERE id IN(" . $ids . ")";
            db_query($q);
            echo '<p>zapped the relationship between the publication type and the commenting settings entity table.</p>';
            // delete rows from commenting_settings where id corresponds to a publication id
        }
    }
} else {
    echo_form();
/**
 * Attempt to attach a thumbnail to the media work.
 *
 * @param $obj object
 * @param $media_work entity
 * @param $netid string
 */
function attach_thumbnail($obj, $media_work, $netid)
{
    // check to see if this had thumbnails generated
    if (property_exists($obj, 'thumbnails')) {
        // First, create temp file
        $tmp_path = ZencoderShim::get_temp_dir() . 'temp_media_image_' . $media_work->get_value('entry_id') . '.jpg';
        $f = fopen($tmp_path, 'w');
        $image_url = $obj->thumbnails[0]->images[0]->url;
        $contents = get_reason_url_contents($image_url);
        fwrite($f, $contents);
        fclose($f);
        // Then, create image entity.  Attach it to the media work, too.
        if (!empty($tmp_path) and file_exists($tmp_path)) {
            // Create a new entity for the image
            if ($id = create_image_entity($media_work, $netid)) {
                $im = new ImageManager();
                //$im->convert_non_web_to = $this->convert_non_web_to;
                $im->thumbnail_width = REASON_STANDARD_MAX_THUMBNAIL_WIDTH;
                $im->thumbnail_height = REASON_STANDARD_MAX_THUMBNAIL_HEIGHT;
                $im->max_width = REASON_STANDARD_MAX_IMAGE_WIDTH;
                $im->max_height = REASON_STANDARD_MAX_IMAGE_HEIGHT;
                $im->load_by_type(id_of('image'), $id, get_user_id($netid));
                $im->handle_standard_image($id, $tmp_path);
                //$im->handle_original_image($id, $image);
                $im->create_default_thumbnail($id);
                $dimensions = $obj->thumbnails[0]->images[0]->dimensions;
                $arr = explode('x', $dimensions);
                $thumb_width = intval($arr[0]);
                $thumb_height = intval($arr[1]);
                if ($thumb_width > $im->max_width || $thumb_height > $im->max_height) {
                    $image_path = PHOTOSTOCK . reason_format_image_filename($id, 'jpg');
                    $original_path = add_name_suffix($image_path, '_orig');
                    @copy($image_path, $original_path);
                    resize_image($image_path, $im->max_width, $im->max_height);
                }
                // Pull the values generated in the content manager
                // and save them to the entity
                $values = array();
                foreach ($im->get_element_names() as $element_name) {
                    $values[$element_name] = $im->get_value($element_name);
                }
                reason_update_entity($id, get_user_id($netid), $values, false);
                // Remove any existing association with an image and replace it with this new one
                delete_relationships(array('entity_a' => $media_work->id(), 'type' => relationship_id_of('av_to_primary_image')));
                create_relationship($media_work->id(), $id, relationship_id_of('av_to_primary_image'));
            } else {
                trigger_error('Failed to create image entity.');
            }
        } else {
            trigger_error('No path to image: ' . $tmp_path);
        }
    }
}
예제 #10
0
 function delete_associations_of_type($reln_unique_name)
 {
     delete_relationships(array('entity_a' => $this->entity->id(), 'type' => relationship_id_of($reln_unique_name)));
 }
 function process_form(&$disco)
 {
     $images = $this->get_images();
     $thumbnail_image = $images[$disco->get_value('thumbnails')];
     $tmp_path = WEB_PATH . trim_slashes(WEB_TEMP) . '/temp_media_image_' . uniqid() . '.jpg';
     $contents = get_reason_url_contents($thumbnail_image);
     if (!$contents) {
         trigger_error('Unable to retrieve file contents for ' . $thumbnail_image . '. The url is invalid or S3 is being slow.');
         return;
     }
     $f = fopen($tmp_path, 'w');
     fwrite($f, $contents);
     fclose($f);
     if (!empty($tmp_path) and file_exists($tmp_path)) {
         // Create a new entity for the image
         if ($id = $this->create_image_entity()) {
             $im = new ImageManager();
             //$im->convert_non_web_to = $this->convert_non_web_to;
             $im->thumbnail_width = REASON_STANDARD_MAX_THUMBNAIL_WIDTH;
             $im->thumbnail_height = REASON_STANDARD_MAX_THUMBNAIL_HEIGHT;
             $im->max_width = REASON_STANDARD_MAX_IMAGE_WIDTH;
             $im->max_height = REASON_STANDARD_MAX_IMAGE_HEIGHT;
             $im->load_by_type(id_of('image'), $id, $this->user->id());
             $im->handle_standard_image($id, $tmp_path);
             //$im->handle_original_image($id, $image);
             $im->create_default_thumbnail($id);
             $image_path = PHOTOSTOCK . reason_format_image_filename($id, 'jpg');
             $original_path = add_name_suffix($image_path, '_orig');
             @copy($image_path, $original_path);
             resize_image($image_path, $im->max_width, $im->max_height);
             // Pull the values generated in the content manager
             // and save them to the entity
             $values = array();
             foreach ($im->get_element_names() as $element_name) {
                 $values[$element_name] = $im->get_value($element_name);
             }
             reason_update_entity($id, $this->user->id(), $values, false);
             // Remove any existing association with an image and replace it with this new one
             delete_relationships(array('entity_a' => $this->media_work->id(), 'type' => relationship_id_of('av_to_primary_image')));
             create_relationship($this->media_work->id(), $id, relationship_id_of('av_to_primary_image'));
         } else {
             trigger_error('Failed to create image entity.');
         }
     } else {
         trigger_error('No path to image: ' . $tmp_path);
     }
 }
 /**
  * Uploads the media work to Kaltura.
  */
 function _process_work($filepath, $remote_url)
 {
     // Remove the old associated image if it was a thumbnail
     $es = new entity_selector();
     $es->add_type(id_of('image'));
     $es->add_right_relationship($this->manager->get_value('id'), relationship_id_of('av_to_primary_image'));
     $cur_image = current($es->run_one());
     if ($cur_image && strpos($cur_image->get_value('name'), 'Thumbnail)') !== false) {
         delete_relationships(array('entity_a' => $this->manager->get_value('id'), 'type' => relationship_id_of('av_to_primary_image')));
     }
     $user = new entity($this->manager->admin_page->authenticated_user_id);
     $media_work = new entity($this->manager->get_value('id'));
     if ($this->manager->get_value('av_type') == 'Video') {
         $entry = $this->kaltura_shim->upload_video($filepath, $media_work, $user->get_value('name'), $remote_url);
     } elseif ($this->manager->get_value('av_type') == 'Audio') {
         $entry = $this->kaltura_shim->upload_audio($filepath, $media_work, $user->get_value('name'), $remote_url);
     } else {
         $this->manager->set_error('av_type', 'The Media Type field is required.');
         return;
     }
     if (!$entry) {
         if ($this->manager->get_value('upload_file')) {
             $this->manager->set_error('upload_file', 'There was an error during the upload process.');
         } else {
             $this->manager->set_error('upload_url', 'There was an error during the upload process.');
         }
         return;
     }
     // If there are already entries in Kaltura for this Media Work, we should delete them
     // and remove the Media Files from Reason, too.
     if (!empty($this->initial_metadata['id'])) {
         $this->_remove_existing_media($this->manager->get_value('entry_id'));
     }
     $this->manager->set_value('tmp_file_name', $media_work->get_value('tmp_file_name'));
     $this->_update_fields_with_file_data($entry);
 }
예제 #13
0
 function do_unassociate()
 {
     list($entity_a, $entity_b, $rel_info) = $this->get_entities();
     if (!$this->_cur_user_has_privs($entity_a, $entity_b, $rel_info)) {
         return false;
     }
     delete_relationships(array('entity_a' => $entity_a->id(), 'entity_b' => $entity_b->id(), 'type' => $rel_info['id']));
 }
예제 #14
0
 function remove_sortable_table_from_blurbs()
 {
     echo '<hr/>';
     $tables = get_entity_tables_by_type(id_of('text_blurb'), false);
     // no cache
     if (!in_array("sortable", $tables)) {
         echo "<p>The text blurb type does not use the entity table sortable - this script has probably been run</p>";
     } else {
         $es = new entity_selector();
         $es->add_type(id_of('content_table'));
         $es->add_relation('entity.name = "sortable"');
         $es->add_right_relationship(id_of('text_blurb'), relationship_id_of('type_to_table'));
         $es->set_num(1);
         $es->limit_tables();
         $es->limit_fields();
         $result = $es->run_one();
         if (!empty($result)) {
             $table = current($result);
             // grab all text blurb entities
             $es2 = new entity_selector();
             $es2->add_type(id_of('text_blurb'));
             $es2->limit_tables();
             $es2->limit_fields();
             $result2 = $es2->run_one();
             $ids = implode(",", array_keys($result2));
             $q = "DELETE from sortable WHERE id IN(" . $ids . ")";
             if ($this->mode == "test") {
                 echo "<p>Would delete all relationships between the text blurb type and the sortable entity table across type_to_table<p>";
                 echo "<p>Would also run this query to zap all the entities in the sortable table that correspond to text blurbs:</p>";
                 echo "<p>" . $q . "</p>";
             } else {
                 delete_relationships(array('entity_a' => id_of('text_blurb'), 'entity_b' => $table->id(), 'type' => relationship_id_of('type_to_table')));
                 db_query($q);
                 echo "<p>Deleted type_to_table relationship bewteen text blurbs and sortable, and the corresponding sortable entities</p>";
             }
         } else {
             echo '<p>Could not find the entity table even though get_entity_tables_by_type says that it exists. Doing nothing.</p>';
         }
     }
 }
 function associate_image($media_work, $data)
 {
     $tmp_path = KalturaShim::get_temp_dir() . 'temp_media_image_' . $media_work->get_value('entry_id') . '.jpg';
     $f = fopen($tmp_path, 'w');
     $thumb_opts = array('width' => $data['width'], 'quality' => 100);
     $image_url = $this->kaltura_shim->get_thumbnail($media_work->get_value('entry_id'), $data['length_in_msecs'] / 2.0 / 1000.0, $thumb_opts);
     $contents = get_reason_url_contents($image_url);
     fwrite($f, $contents);
     fclose($f);
     if (!empty($tmp_path) and file_exists($tmp_path)) {
         // Create a new entity for the image
         if ($id = $this->create_image_entity($media_work, $data)) {
             $im = new ImageManager();
             //$im->convert_non_web_to = $this->convert_non_web_to;
             $im->thumbnail_width = REASON_STANDARD_MAX_THUMBNAIL_WIDTH;
             $im->thumbnail_height = REASON_STANDARD_MAX_THUMBNAIL_HEIGHT;
             $im->max_width = REASON_STANDARD_MAX_IMAGE_WIDTH;
             $im->max_height = REASON_STANDARD_MAX_IMAGE_HEIGHT;
             $im->load_by_type(id_of('image'), $id, get_user_id($data['puser_id']));
             $im->handle_standard_image($id, $tmp_path);
             //$im->handle_original_image($id, $image);
             $im->create_default_thumbnail($id);
             if ($data['width'] > $im->max_width || $data['height'] > $im->max_height) {
                 $image_path = PHOTOSTOCK . reason_format_image_filename($id, 'jpg');
                 $original_path = add_name_suffix($image_path, '_orig');
                 @copy($image_path, $original_path);
                 resize_image($image_path, $im->max_width, $im->max_height);
             }
             // Pull the values generated in the content manager
             // and save them to the entity
             $values = array();
             foreach ($im->get_element_names() as $element_name) {
                 $values[$element_name] = $im->get_value($element_name);
             }
             reason_update_entity($id, get_user_id($data['puser_id']), $values, false);
             // Remove any existing association with an image and replace it with this new one
             delete_relationships(array('entity_a' => $media_work->id(), 'type' => relationship_id_of('av_to_primary_image')));
             create_relationship($media_work->id(), $id, relationship_id_of('av_to_primary_image'));
         } else {
             trigger_error('Failed to create image entity.');
         }
     } else {
         trigger_error('No path to image: ' . $tmp_path);
     }
 }