/** * 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'll get our site URLs using the url_builder to save some time. * * We also will cache the urls for url_cache_lifespan so that only the first load has the overhead of URL building. */ function get_site_urls() { $roc = new ReasonObjectCache($this->admin_page->site_id . '_google_analytics_site_url_info', $this->url_cache_lifespan); $urls = $roc->fetch(); if (!$urls) { $es = new entity_selector($this->admin_page->site_id); $es->limit_fields(array('url', 'url_fragment')); $es->add_type(id_of('minisite_page')); $es->add_left_relationship_field('minisite_page_parent', 'entity', 'id', 'parent_id'); $es->add_relation('(entity.name != "") AND ((url.url = "") OR (url.url IS NULL))'); // only pages, not custom urls $this->pages = $es->run_one(); $url_builder = new reasonPageURL(); $url_builder->provide_page_entities($pages); foreach ($this->pages as $id => $page) { $url_builder->set_id($id); $url = $url_builder->get_relative_url(); $urls[$id] = $url; } $roc->set($urls); } return $urls; }