Esempio n. 1
0
 /**
  * Gets all relationships where current item is on left side
  * @param $var makes sure current type is in ar.relationship_a by default...not sure if this is non-default somewhere
  */
 function get_backward_rels($var = 'default')
 {
     // get allowable relationships
     $q = new DBSelector();
     $q->add_table('ar', 'allowable_relationship');
     $q->add_table('e', 'entity');
     $q->add_table('site_own_alrel', 'allowable_relationship');
     $q->add_table('r', 'relationship');
     $q->add_field('ar', '*');
     $q->add_field('e', 'name', 'entity_name');
     if ($var == 'default') {
         $q->add_relation('ar.relationship_b = ' . $this->type_id);
     } else {
         $q->add_relation('ar.relationship_b = ' . $this->request[CM_VAR_PREFIX . 'type_id']);
     }
     $q->add_relation('ar.relationship_a = e.id');
     $q->add_relation('ar.directionality = "bidirectional"');
     if (reason_relationship_names_are_unique()) {
         $q->add_relation('ar.type = "association"');
         $q->set_order('ar.id ASC');
     } else {
         $q->add_relation('ar.name != "owns"');
         $q->add_relation('ar.name != "borrows"');
         $q->add_relation('ar.name NOT LIKE "%archive%"');
     }
     // make sure this site has access to the related type
     // we don't want to be able to associate with types that a site does not have access to
     $q->add_relation('site_own_alrel.relationship_a = ' . id_of('site'));
     $q->add_relation('site_own_alrel.relationship_b = ' . id_of('type'));
     $q->add_relation('site_own_alrel.name = "site_to_type"');
     $q->add_relation('r.entity_a = ' . $this->site_id);
     $q->add_relation('r.entity_b = ar.relationship_a');
     $q->add_relation('r.type = site_own_alrel.id');
     $q->add_relation('(ar.custom_associator IS NULL OR ar.custom_associator = "")');
     $r = db_query($q->get_query(), 'Unable to get allowable relationships for this type.');
     $x = array();
     while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {
         $x[] = $row;
     }
     $this->reverse_associations = $x;
     return $x;
 }
 function clean_extra_contiguous_values()
 {
     $dbs = new DBSelector();
     $dbs->add_table('URL_history', 'URL_history');
     $dbs->add_field('URL_history', 'page_id');
     $dbs->add_field('URL_history', 'id');
     $dbs->add_field('URL_history', 'timestamp');
     $dbs->add_field('URL_history', 'url');
     $dbs->set_order('page_id DESC, timestamp DESC');
     $rows = $dbs->run();
     $page_id = NULL;
     $url = NULL;
     if ($rows) {
         foreach ($rows as $row) {
             // if the page id is the same as last page id and url is the same as last url - this one gets queued for deletion
             $last_page_id = $page_id;
             $page_id = $row['page_id'];
             $last_url = $url;
             $url = $row['url'];
             if ($last_page_id == $page_id && $last_url == $url) {
                 $needs_deletion[] = $row['id'];
             }
         }
     }
     if (isset($needs_deletion)) {
         $deleter_sql = 'DELETE FROM URL_history WHERE id IN ("' . implode('","', $needs_deletion) . '")';
         if ($this->mode == 'test') {
             echo '<p>Would delete ' . count($needs_deletion) . ' unneeded contiguous rows with this query:</p>';
             echo $deleter_sql;
         }
         if ($this->mode == 'run') {
             db_query($deleter_sql, 'Could not delete rows from URL_history');
             echo '<p>Deleted ' . count($needs_deletion) . ' unneeded contiguous rows with this query:</p>';
             echo $deleter_sql;
         }
     } else {
         echo '<p>There are no unneeded contiguous rows in the URL_history table that need deletion - you may have already run this script</p>';
         return true;
     }
 }
Esempio n. 3
0
 /**
  * Initialize the _right_relationships and _right_relationships_info arrays
  * @access private
  * @todo cache db structure info so it doesn't need to rediscover it every time
  */
 function _init_right_relationships()
 {
     //first, get relationship types
     $dbq = new DBSelector();
     $dbq->add_field('allow', '*');
     $dbq->add_table('allow', 'allowable_relationship');
     $dbq->add_table('entity', 'entity');
     $dbq->add_relation('entity.id = ' . $this->_id);
     $dbq->add_relation('entity.type = allow.relationship_b');
     // we think this should be commented out.  it makes an error not appear.  you probably want more than that.  i don't have it.
     //$dbq->add_relation( 'entity.state = "Live"' );
     $r1 = db_query($dbq->get_query(), 'Entity Error:  Could not get relationships');
     $rel_name = array();
     while ($row = mysql_fetch_array($r1, MYSQL_ASSOC)) {
         $this->_right_relationships[$row['id']] = array();
         $this->_right_relationships[$row['name']] = array();
         $this->_right_relationships_info[$row['id']] = array();
         $this->_right_relationships_info[$row['name']] = array();
         $rel_name[$row['id']] = $row['name'];
     }
     $dbq = new DBSelector();
     $dbq->add_table('r', 'relationship');
     $dbq->add_field('r', '*');
     $dbq->add_table('entity', 'entity');
     $dbq->add_relation('entity.state = "Live"');
     $dbq->add_relation('entity.id = r.entity_a');
     $dbq->add_relation('r.entity_b = ' . $this->id());
     if ($this->_env['restrict_site'] and !empty($this->_env['site'])) {
         $dbq->add_relation('(r.site=0 OR r.site=' . $this->_env['site'] . ')');
     }
     $dbq->set_order('rel_sort_order');
     $rels = $dbq->run();
     foreach ($rels as $r) {
         $e = new entity($r['entity_a']);
         $this->_right_relationships[$r['type']][] = $e;
         $this->_right_relationships_info[$r['type']][] = $r;
         if (!empty($rel_name[$r['type']])) {
             $this->_right_relationships[$rel_name[$r['type']]][] = $e;
             $this->_right_relationships_info[$rel_name[$r['type']]][] = $r;
         }
     }
 }
	}
	else
	{
		$old_page_id = (integer) $_GET['old_page'];
		$new_page_id = (integer) $_GET['new_page'];
		
		if(empty($old_page_id) || empty($new_page_id))
		{
			echo 'Invalid page id';
			die();
		}
		
		$dbs = new DBSelector();
		$dbs->add_table('URL_history');
		$dbs->add_relation('page_id = "'.addslashes($old_page_id).'"');
		$dbs->set_order('timestamp ASC');
		$rows = $dbs->run();
		//pray($rows);
		echo '<h2>Replicating Page URL History</h2>'."\n";
		echo '<ul>'."\n";
		foreach($rows as $row)
		{
			if(!empty($row['url']))
			{
				$query = 'INSERT INTO URL_history SET ' . 
						'url = "' . addslashes($row['url']) . '", ' .
						'page_id = "' . addslashes($new_page_id) . '", ' .
						'timestamp = "' . addslashes(time()) . '"';
		
				$results = mysql_query( $query );