/** * Get the most recent entry for the page_id - if its URL does not match the URL of the page now, create a new entry and update * the timestamp of the last location (if it exists). * * @todo consider whether or not there is any utility in checking children if we are not creating an entry for the current * location the page * * @param integer $page_id * @param boolean $check_children * @return boolean */ function update_URL_history( $page_id, $check_children = true ) { $page = new entity($page_id); if (reason_is_entity($page, 'minisite_page') && !$page->get_value('url')) { $builder = new reasonPageURL(); $builder->disable_static_cache(); // force a refresh for this instance of the builder in case the URL just changed $builder->set_id($page->id()); $url = $builder->get_relative_url(); if (!empty($url)) // we only bother if we can get a url { // lets grab the most recent entry for this page_id $d = new DBselector(); $d->add_table( 'history', 'URL_history' ); $d->add_field( 'history', 'id', 'id' ); $d->add_field( 'history', 'url', 'url' ); $d->add_field( 'history', 'page_id', 'page_id' ); $d->add_field( 'history', 'timestamp', 'timestamp' ); $d->add_relation( 'history.page_id = ' . $page_id ); $d->set_num(1); $d->set_order( 'history.timestamp DESC, history.id DESC' ); // get highest id of highest timestamp $result = db_query( $d->get_query() , 'Error getting most recent URL_history entry for page '.$page_id ); if( $row = mysql_fetch_assoc($result)) { $create_new = ($row['url'] == $url) ? false : true; $update_old = $create_new; // if we create new in this case we want to update the old as well } else { $create_new = true; $update_old = false; } if ($create_new) // lets use the SQLer to do this { $sqler = new SQLER(); $cur_time = time(); $values = array('url' => $url, 'page_id' => $page_id, 'timestamp' => $cur_time); $sqler->insert('URL_history', $values); if ($update_old) // the old row is the one we already grabbed - lets update its timestamp to be just before what we just created { $sqler->update_one('URL_history', array('timestamp' => ($cur_time - 1)), $row['id']); } } if( $check_children ) update_children( $page_id ); return true; } } trigger_error('update_URL_history called on entity id ' . $page_id . ' which does not appear to be a valid minisite_page entity with a url (is it an external URL?)'); return false; }
/** * We use a DBSelector to construct a super basic query to quickly get the owner id. * * This method probably ought to be a method directly on minisite page entities ... but alas we aren't there yet. * For efficiency sake, we could eliminate this if the owner was stored on the page entity and not across a relationship * * @access private * @param object minisite_page entity * @return int owner id for a minisite page */ function _get_owner_id(&$page) { if (!$page->has_value('owner_id')) { $d = new DBselector(); $d->add_table( 'r', 'relationship' ); $d->add_field( 'r', 'entity_a', 'owner_id' ); $d->add_relation( 'r.type = ' . get_owns_relationship_id(id_of('minisite_page'))); $d->add_relation( 'r.entity_b = ' . $page->id() ); $d->set_num(1); $result = db_query( $d->get_query() , 'Error getting owner ID.' ); if( $row = mysql_fetch_assoc($result)) { $page->set_value('owner_id', $row['owner_id']); } else { $page->set_value('owner_id', false); } } return $page->get_value('owner_id'); }
/** * We always return true - we check if the entity id is a root node (and then if the destination has a root node) and delete the page parent rel if so. */ function run_job() { $d = new DBselector(); $d->add_table('r', 'relationship'); $d->add_field('r', 'entity_b', 'parent_id'); $d->add_field('r', 'id', 'rel_id'); $d->add_relation('r.type = ' . relationship_id_of('minisite_page_parent')); $d->add_relation('r.entity_a = ' . $this->config('page_id')); $d->set_num(1); $result = db_query($d->get_query(), 'Error getting parent ID.'); if ($row = mysql_fetch_assoc($result)) { if ($row['parent_id'] == $this->config('page_id')) { if ($this->new_site_has_root_node()) { delete_relationship($row['rel_id']); $this->set_report("Page ID " . $this->config('page_id') . " is a root node - deleted rel " . $row['rel_id'] . '.'); } else { $this->set_report("Page ID " . $this->config('page_id') . " remains a root node - not deleting because destination site has no root node."); } } } return true; }