Пример #1
0
 function init()
 {
     if (!empty($this->admin_page->id)) {
         $temp = new entity($this->admin_page->id, false);
         if ($temp->get_value('new') && $temp->get_value('state') == 'Pending' && !$temp->get_value('name') && reason_user_has_privs($this->admin_page->user_id, 'delete_pending')) {
             reason_expunge_entity($this->admin_page->id, $this->admin_page->user_id);
         }
     }
     if (!empty($this->admin_page->request[CM_VAR_PREFIX . 'type_id'])) {
         $old_vars = array();
         foreach ($this->admin_page->request as $key => $val) {
             if (substr($key, 0, strlen(CM_VAR_PREFIX)) == CM_VAR_PREFIX) {
                 $old_vars[substr($key, strlen(CM_VAR_PREFIX))] = $val;
                 $old_vars[$key] = '';
             }
         }
         foreach ($this->admin_page->default_args as $arg) {
             if (!isset($old_vars[$arg])) {
                 $old_vars[$arg] = '';
             }
         }
         $link = $this->admin_page->make_link($old_vars);
     } else {
         $link = $this->admin_page->make_link(array('id' => '', 'site_id' => $this->admin_page->site_id, 'type_id' => $this->admin_page->type_id, 'cur_module' => 'Lister'));
     }
     header('Location: ' . unhtmlentities($link));
     die;
 }
Пример #2
0
 /**
  * Run the upgrader
  * @return string HTML report
  */
 public function run()
 {
     if ($loki_1_entity = $this->get_loki_1_entity()) {
         reason_expunge_entity($loki_1_entity->id(), $this->user_id());
         return '<p>Deleted the loki 1 html editor entity.</p>';
     } else {
         return '<p>Your instance doesn\'t have the loki 1 html editor entity - this script has probably been run.</p>';
     }
 }
 function run_job()
 {
     $es = new entity_selector($this->site_id);
     $es->add_type(id_of('news'));
     $result = $es->run_one();
     if ($result) {
         $ids = array_keys($result);
         foreach ($result as $id => $item) {
             reason_expunge_entity($id, $this->user_id);
         }
     }
     $es = new entity_selector($this->site_id);
     $es->add_type(id_of('publication_type'));
     $result = $es->run_one();
     if ($result) {
         $ids = array_keys($result);
         foreach ($result as $id => $item) {
             reason_expunge_entity($id, $this->user_id);
         }
     }
     $es = new entity_selector($this->site_id);
     $es->add_type(id_of('category_type'));
     $result = $es->run_one();
     if ($result) {
         $ids = array_keys($result);
         foreach ($result as $id => $item) {
             reason_expunge_entity($id, $this->user_id);
         }
     }
     $es = new entity_selector($this->site_id);
     $es->add_type(id_of('comment_type'));
     $result = $es->run_one();
     if ($result) {
         $ids = array_keys($result);
         foreach ($result as $id => $item) {
             reason_expunge_entity($id, $this->user_id);
         }
     }
     $es = new entity_selector($this->site_id);
     $es->add_type(id_of('minisite_page'));
     $result = $es->run_one();
     if ($result) {
         $root_page = root_finder($this->site_id);
         $ids = array_keys($result);
         foreach ($result as $id => $item) {
             if ($id != $root_page) {
                 reason_expunge_entity($id, $this->user_id);
             }
         }
     }
     $this->set_report('Zapped all the news, publications, categories, comments, and pages from the site');
 }
Пример #4
0
	/** Removes entity with id = $id and all relationships with that id from the database.
	 *
	 *	Specifically, deletes the entry from the entity table and all sub-tables.
	 *	Also deletes all relationships where entity_a or entity_b = id
	 *
	 *	@todo add logging of expungements so that these important actions are traceable
	 *
	 *	@param	integer	$id		The ID of the entity to delete
	 *	@param	integer	$user_id		The ID of the reason user who is deleting the item
	 *	@return		array	the entity and all relationships of the entity just deleted
	 */
	function reason_expunge_entity( $id, $user_id )
	{
		$testmode = false;
		
		if(empty($user_id) || !is_numeric($user_id) || $user_id < 1 )
		{
			trigger_error('Expungement without providing a Reason user id is deprecated. Future releases of Reason will not allow entities to be expunged without providing a user id');
		}
		
		// get all entity information before deleting it
		
		$id = (integer) $id;
		if(empty($id) || $id < 1)
		{
			trigger_error('ID passed to reason_expunge_entity() not a positive integer. Unable to expunge.');
			return false;
		}

		$entity = get_entity_by_id( $id, false );
		
		if(empty($entity['id']))
		{
			trigger_error('Entity id '.$id.' does not exisit; unable to expunge.');
			return false;
		}
		
		$sqler = new SQLER;

		$archives = array();
		$q = "SELECT r.entity_b, r.type, ar.name FROM relationship AS r,  allowable_relationship AS ar WHERE r.entity_a = $id AND r.type = ar.id";
		$r = db_query( $q, 'Unable to retrieve entity left relationships for expungement' );
		while( $row = mysql_fetch_array( $r, MYSQL_ASSOC ) )
		{
			$entity[ 'left_relationships' ][] = $row;
			// this is an archive - mark it for deletion.
			if( strpos( $row[ 'name' ], 'archive' ) !== false )
				$archives[] = $row[ 'entity_b' ];
		}
		
		$q = "SELECT entity_a, type FROM relationship WHERE entity_b = $id";
		$r = db_query( $q, 'Unable to retrieve entity right relationships for expungement' );
		while( $row = mysql_fetch_array( $r, MYSQL_ASSOC ) )
			$entity[ 'right_relationships' ][] = $row;

		// call custom deletion action
		$type = get_entity_by_id( $entity[ 'type' ] );

		if( $type[ 'custom_deleter' ] )
			reason_include_once( 'content_deleters/'.$type['custom_deleter'] );

		// delete from entity table
		$q = "DELETE FROM entity WHERE id = $id";
		if( $testmode )
			echo $q.'<br /><br />';
		else
			db_query( $q, 'Unable to delete entity from entity table.' );

		// delete from sub tables
		$tables = get_entity_tables_by_type( $entity['type'] );

		foreach( $tables as $table )
		{
			if( $table != 'entity' )
			{
				if( $testmode )
					echo '$sqler->delete_one( "'.htmlspecialchars($table).'",'.$id.' )<br /><br />';
				else
					$sqler->delete_one( $table, $id );
			}
		}

		// delete relationships
		$q = "DELETE FROM relationship WHERE entity_a = $id OR entity_b = $id";
		if( $testmode )
			echo $q.'<br /><br />';
		else
			db_query( $q, 'Unable to delete relationships of entity '.$id );

		// delete all archived entities
		foreach( $archives AS $archive )
			reason_expunge_entity( $archive, $user_id );

		// If the recently-expunged entity is live or pending and has a unique_name, let's refresh_reason_unique_names
		if (!empty($entity['unique_name']) && ( !empty($entity['state']) && (($entity['state'] == 'Pending') || ($entity['state'] == 'Live'))))
		{
			reason_refresh_unique_names();
		}

		return $entity;
	} //
Пример #5
0
 /**
  * Deletes a media work's attached media files and the actual entry in kaltura.
  */
 public function delete_media_work($media_work_deleter)
 {
     $e = new entity($media_work_deleter->get_value('id'));
     $es = new entity_selector();
     $es->add_type(id_of('av_file'));
     $es->add_right_relationship($media_work_deleter->get_value('id'), relationship_id_of('av_to_av_file'));
     $media_files = $es->run_one();
     foreach ($media_files as $file) {
         reason_expunge_entity($file->id(), $media_work_deleter->admin_page->user_id);
     }
     if ($e->get_value('entry_id')) {
         $shim = new KalturaShim();
         $user = new entity($media_work_deleter->admin_page->user_id);
         $shim->delete_media($e, $user->get_value('name'));
     }
 }
Пример #6
0
 protected function delete_all_section_entities()
 {
     $user = get_user_id('causal_agent');
     foreach ($this->get_existing_section_ids() as $id) {
         reason_expunge_entity($id, $user);
     }
 }
 /**
  * Move the field location in the location entity table to the event table and then delete the location entity table. 
  */
 function move_location_field_to_event()
 {
     $fields = get_fields_by_content_table('event');
     if (in_array('location', $fields)) {
         echo '<p>The event entity table already has the location field - the script has probably been run</p>';
         $es = new entity_selector();
         $es->add_type(id_of('event_type'));
         $es->set_num(5);
         $es->add_relation('event.location IS NOT NULL');
         $result = $es->run_one();
     } elseif ($this->mode == 'run') {
         // grab all locations from the location.location table for events
         $es = new entity_selector();
         $es->add_type(id_of('event_type'));
         $es->limit_tables(array('location'));
         $es->limit_fields(array('location.location'));
         $es->add_relation(' ((location.location IS NOT NULL) AND (location.location != ""))');
         $result = $es->run_one('', 'All');
         // All does not get archived entities ... hmmm
         $result2 = $es->run_one('', 'Archived');
         // populate $ids - an array of entity ids to location value, with it we can do a direct update of the event entity table
         foreach ($result as $k => $v) {
             $ids[$k] = $v->get_value('location');
         }
         foreach ($result2 as $k2 => $v2) {
             $ids[$k2] = $v2->get_value('location');
         }
         unset($es);
         unset($result);
         unset($result2);
         // lets find our table entity
         $es = new entity_selector();
         $es->add_type(id_of('content_table'));
         $es->add_relation('entity.name = "location"');
         $es->set_num(1);
         $location_result = $es->run_one();
         $es2 = new entity_selector();
         $es2->add_type(id_of('content_table'));
         $es2->add_relation('entity.name = "event"');
         $es2->set_num(1);
         $event_result = $es2->run_one();
         if ($location_result && $event_result) {
             $location_table = reset($location_result);
             $event_result = reset($event_result);
             $field_to_entity_table_id = relationship_id_of('field_to_entity_table');
             $es3 = new entity_selector();
             $es3->add_type(id_of('field'));
             $es3->add_relation('entity.name = "location"');
             $es3->add_left_relationship($location_table->id(), $field_to_entity_table_id);
             $es3->set_num(1);
             $es3_result = $es3->run_one();
             if ($es3_result) {
                 $field = reset($es3_result);
                 // create the column on the event table
                 $q = "ALTER TABLE event ADD location " . $field->get_value('db_type');
                 $r = db_query($q, 'Problems - could not add the location column to the event table');
                 $sqler = new SQLER();
                 // populate the values for the new column
                 if (isset($ids)) {
                     foreach ($ids as $id => $location) {
                         $sqler->update_one('event', array('location' => $location), $id);
                     }
                 }
                 // update the entity table for the field_to_entity_table_relationship at hand
                 $q = 'UPDATE relationship SET entity_b=' . $event_result->id();
                 $q .= ' WHERE entity_a=' . $field->id() . ' AND entity_b=' . $location_table->id() . ' AND type=' . $field_to_entity_table_id;
                 db_query($q);
                 // create the column on the event table
                 $q = "DROP TABLE location";
                 $r = db_query($q, 'Could not drop the entity table location');
                 reason_expunge_entity($location_table->id(), $this->reason_id);
                 echo '<p>Moved location.location to event.location, and deleted the location entity table</p>';
             }
         }
     } elseif ($this->mode == 'test') {
         echo '<p>Would move the location.location to event.location, and delete the location entity table</p>';
     }
 }
Пример #8
0
 function delete_orphan($orphan_id)
 {
     if (empty($this->_user_id)) {
         trigger_error('Must set user id before calling delete_orphan()');
         return false;
     }
     if (!get_owner_site_id($orphan_id)) {
         return reason_expunge_entity($orphan_id, $this->_user_id);
     } else {
         trigger_error($orphan_id . ' not actually an orphan');
         return false;
     }
 }
$notification = $zencoder->notifications->parseIncoming();
$output = current($notification->job->outputs);
$media_work = get_media_work($notification->job->id);
if ($media_work) {
    $user = new entity($media_work->get_value('created_by'));
    $netid = $user->get_value('name');
    // first check to see if all successfully transcoded
    if ($output->state == "skipped") {
        echo 'This output was skipped because of conditional outputs.' . "\n";
        $output = current($notification->job->outputs);
        $label = $output->label;
        $label_parts = explode('_', $label);
        $format = reset($label_parts);
        $id = end($label_parts);
        echo 'Expunging Media File ' . $id . "\n";
        reason_expunge_entity($id, $user->id());
    } elseif ($output->state != "finished") {
        echo 'Output ' . $output->id . ' for job ' . $notification->job->id . ' not successful in encoding.' . "\n";
        echo 'There were errors or cancellations in the transcoding process.' . "\n";
        set_error($media_work);
    } else {
        if ($media_work->get_value('av_type') == 'Video') {
            process_video($media_work, $notification, $mime_type_map, $netid);
        } elseif ($media_work->get_value('av_type') == 'Audio') {
            process_audio($media_work, $notification, $mime_type_map, $netid);
        } else {
            echo 'Media Work with id ' . $media_work->id() . ' has invalid av_type.' . "\n";
            set_error($media_work);
        }
    }
} else {
Пример #10
0
/**
 * If the enable_comment_notification field exists, then zap it - will only be the case if an earlier version of this script was run
 *
 */
function zap_field($entity_table_name, $field_name, $reason_user_id)
{
    $es = new entity_selector();
    $es->add_type(id_of('content_table'));
    $es->add_relation('entity.name = "' . $entity_table_name . '"');
    $es->set_num(1);
    $es->limit_tables();
    $es->limit_fields();
    $result = $es->run_one();
    if (empty($result)) {
        echo '<p>The entity table ' . $entity_table_name . ' does not exist - field ' . $field_name . ' could not be zapped</p>';
        return false;
    } else {
        $et = current($result);
        $es2 = new entity_selector();
        $es2->add_type(id_of('field'));
        $es2->add_relation('entity.name = "' . $field_name . '"');
        $es2->add_left_relationship($et->id(), relationship_id_of('field_to_entity_table'));
        $es2->set_num(1);
        //$es2->limit_tables();
        //$es2->limit_fields();
        $result2 = $es2->run_one();
        if (empty($result2)) {
            echo '<p>The field ' . $field_name . ' does not exist in entity table ' . $entity_table_name . ' and could not be zapped</p>';
            return false;
        } else {
            $res = current($result2);
            $q = "ALTER TABLE " . $entity_table_name . " DROP " . $field_name;
            db_query($q);
            reason_expunge_entity($res->id(), $reason_user_id);
            // also deletes all relationships to the field, which fixes the entity table
            echo '<p>Zapped field ' . $field_name . ' in entity table ' . $entity_table_name . '<p>';
        }
    }
}
Пример #11
0
 public function upload_media($disco)
 {
     $username = reason_check_authentication();
     if (empty($username)) {
         $this->_user_id = make_sure_username_is_user('anonymous', $this->site_id);
     } else {
         $this->_user_id = make_sure_username_is_user($username, $this->site_id);
     }
     // Begin the upload to whatever serivice is being used
     $at_remote_url = false;
     if ($disco->get_element('upload_file')->tmp_full_path) {
         $tmp_path_arr = explode("/", $disco->get_element('upload_file')->tmp_full_path);
         $this->_filename = $this->sanitize_filename($disco->get_element('upload_file')->file['name']);
         $this->_filepath = $this->get_media_import_dir() . $this->_filename;
         rename($disco->get_element('upload_file')->tmp_full_path, $this->_filepath);
     } else {
         $at_remote_url = true;
         $this->_filename = basename($disco->get_value('url'));
         $this->_filepath = $disco->get_value('url');
     }
     $media_work_id = $this->_create_media_entity($disco);
     if ($disco->get_value('av_type') == 'Video') {
         $this->_entry = $this->shim->upload_video($this->_filepath, new entity($this->_media_work_id), $username, $at_remote_url);
     } else {
         $this->_entry = $this->shim->upload_audio($this->_filepath, new entity($this->_media_work_id), $username, $at_remote_url);
     }
     if (!$this->_entry) {
         $disco->set_error('upload_file', 'There was an error during the upload process.');
         reason_expunge_entity($this->_media_work_id, $this->_user_id);
         $this->_media_work_id = false;
         return;
     }
     $values = array();
     $values['entry_id'] = $this->_entry->id;
     $values['transcoding_status'] = 'converting';
     $values['media_publication_datetime'] = date('Y-m-d H:i:s');
     $values['show_hide'] = $this->params['show_hide_default'];
     reason_update_entity($this->_media_work_id, $this->_user_id, $values, false);
 }
    }
} else {
    $user_id = get_user_id('causal_agent');
}
if (!defined('REASON_DELETED_ITEM_EXPUNGEMENT_WAIT_DAYS')) {
    echo '<p>Note: REASON_DELETED_ITEM_EXPUNGEMENT_WAIT_DAYS not defined; defaulting to 14 days</p>' . "\n";
    $wait_days = 14;
} else {
    $wait_days = REASON_DELETED_ITEM_EXPUNGEMENT_WAIT_DAYS;
    if (empty($wait_days) || !is_numeric($wait_days)) {
        echo '<p>Note: REASON_DELETED_ITEM_EXPUNGEMENT_WAIT_DAYS not set as a number of days; defaulting to 14 days</p>' . "\n";
        $wait_days = 14;
    }
}
// select all entities to delete
$q = "SELECT\n\tid,\n\tname,\n\tDATE_FORMAT(last_modified,'%M %e, %Y %r') AS last_modified\nFROM\n\tentity\nWHERE\n\t( state = 'Deleted' AND \n\t  last_modified < DATE_SUB(NOW(), INTERVAL " . $wait_days . " DAY) ) OR\n\t( state = 'Pending' AND name = '' AND last_modified < DATE_SUB(NOW(), INTERVAL 2 DAY) )";
$r = db_query($q, 'Unable to grab items to delete.');
while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {
    echo '<strong>' . $row['name'] . '</strong> was last modified on ' . $row['last_modified'] . '<br />';
    // delete entity
    $deleted_entities[] = reason_expunge_entity($row['id'], $user_id);
    echo '<em>Expunged!</em><br />';
    echo '<br />';
}
// spit out the list of deleted items
if (!empty($deleted_entities)) {
    pray($deleted_entities);
} else {
    echo '<p>No entities expunged</p>';
}
echo '<hr />done<br /><br />';
Пример #13
0
 /**
  * Expunges a Reason media file entity and deletes the actual associated file as well.
  * @param $media_file entity
  * @param $media_work_id int
  * @param $user_id int
  * @param $preserve_original_file boolean
  */
 public function delete_media_file($media_file, $media_work_id, $user_id, $preserve_original_file = false)
 {
     $media_work = new entity($media_work_id);
     if (!($preserve_original_file && $media_file->get_value('flavor_id') == 'original')) {
         self::get_storage_class()->delete_media($media_file->id(), $media_work, $media_file->get_value('flavor_id'));
     }
     reason_expunge_entity($media_file->id(), $user_id);
 }
 /**
  * Deletes any existing media in Kaltura that corresponds with this media work.
  */
 function _remove_existing_media($entry_id)
 {
     // First grab all related Media Files
     $es = new entity_selector();
     $es->add_type(id_of('av_file'));
     $es->add_right_relationship($this->manager->get_value('id'), relationship_id_of('av_to_av_file'));
     $media_files = $es->run_one();
     $user = new entity($this->manager->admin_page->user_id);
     // Delete actual Reason entities for media files
     foreach ($media_files as $entity) {
         reason_expunge_entity($entity->id(), $user->id());
     }
     // Remove Entries from Kaltura
     $this->kaltura_shim->delete_media($entry_id, $user->get_value('name'));
 }
Пример #15
0
 function delete_entity()
 {
     reason_include_once('function_libraries/admin_actions.php');
     reason_expunge_entity($this->get_value('id'), $this->admin_page->user_id);
 }
 protected function _migrate_approvals()
 {
     $raw_fields = get_fields_by_content_table('policies', false);
     if (in_array('datetime', $raw_fields) && in_array('author', $raw_fields)) {
         $policies = $this->_get_approvals_policies();
     } else {
         $policies = array();
     }
     $msg = '';
     foreach ($policies as $policy) {
         $str = $this->_get_approvals_string($policy);
         if (!empty($str)) {
             reason_update_entity($policy->id(), $policy->get_value('last_edited_by'), array('approvals' => $str, 'datetime' => '', 'author' => '', 'last_modified' => $policy->get_value('last_modified')), false);
             $msg = '<p>Moved all datetime/author data into new approvals field</p>' . "\n";
         }
     }
     if (empty($msg)) {
         $msg .= '<p>No policies needed their approvals field migrated.</p>' . "\n";
     }
     $policies_table_entity = $this->_get_policies_table_entity();
     if (empty($policies_table_entity)) {
         trigger_error('Upgrade script has has a major error. The policies table should exist, but does not!');
         $msg .= '<p>There has been a major error in this upgrade. The policies table should have been created, but it has not. Please restore your Reason instance from a backup and try troubleshooting.</p>' . "\n";
         die;
     }
     $es = new entity_selector();
     $es->add_type(id_of('field'));
     $es->add_left_relationship($policies_table_entity->id(), relationship_id_of('field_to_entity_table'));
     $es->add_relation('name = "datetime"');
     $es->set_num(1);
     $datetime_fields = $es->run_one();
     if (!empty($datetime_fields)) {
         $datetime_field = current($datetime_fields);
         reason_expunge_entity($datetime_field->id(), $this->user_id);
         $msg .= '<p>Deleted the policies.datetime field entity.</p>' . "\n";
     }
     if (in_array('datetime', $raw_fields)) {
         $q = 'ALTER TABLE `policies` DROP `datetime`';
         db_query($q, 'Unable to drop datetime field from policies table.');
         $msg .= '<p>Dropped the datetime field from the policies table.</p>' . "\n";
     }
     $es = new entity_selector();
     $es->add_type(id_of('field'));
     $es->add_left_relationship($policies_table_entity->id(), relationship_id_of('field_to_entity_table'));
     $es->add_relation('name = "author"');
     $es->set_num(1);
     $author_fields = $es->run_one();
     if (!empty($author_fields)) {
         $author_field = current($author_fields);
         reason_expunge_entity($author_field->id(), $this->user_id);
         $msg .= '<p>Deleted the policies.author field entity.</p>' . "\n";
     }
     if (in_array('author', $raw_fields)) {
         $q = 'ALTER TABLE `policies` DROP `author`';
         db_query($q, 'Unable to drop author field from policies table.');
         $msg .= '<p>Dropped the author field from the policies table.</p>' . "\n";
     }
     return $msg;
 }
Пример #17
0
 //	else
 //	{
 //		echo 'Was not able to generate ldap filter for '.$group->get_value('course_identifier_strings').'<br />';
 //		$ok_to_delete_field = false;
 //	}
 //}
 if ($ok_to_delete_field) {
     echo 'Finding course_identifier_strings field...<br />';
     $es = new entity_selector();
     $es->add_type(id_of('field'));
     $es->add_relation('name = "course_identifier_strings"');
     $es->set_num(1);
     $fields = $es->run_one();
     if (!empty($fields)) {
         $field = current($fields);
         reason_expunge_entity($field->id(), $user_id);
         echo 'Deleted course_identifier_strings field<br />';
     } else {
         echo 'Couldn\'t find course_identifier_strings field -- possibly already deleted<br />';
     }
     //check for field existence again
     $results = db_query('DESCRIBE user_group');
     $field_exists = false;
     while ($row = mysql_fetch_array($results)) {
         if ($row['Field'] == 'course_identifier_strings') {
             $field_exists = true;
             break;
         }
     }
     if ($field_exists) {
         echo 'course_identifier_strings field still exista in DB<br />';