/** * 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)) { // 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) { $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) { $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; }
/** * Change a property of an allowable relationship * * Note that changing relationship_a, relationship_b, name, or type is not permitted by this function. * * @param integer $rel_id * @param array $values * @return success */ function update_allowable_relationship($rel_id,$values = array()) { if( isset($values['relationship_a']) || isset($values['relationship_b']) || isset($values['name']) || isset($values['type']) ) { trigger_error('update_allowable_relationship does not allow for the change of left-side type, right-side type, name, or relationship type. Rejecting update.'); return false; } $sqler = new SQLER(); return $sqler->update_one('allowable_relationship',$values,$rel_id); }
function modify_allowable_relationship($rel_name, $fields) { $rel_id = relationship_id_of($rel_name); if ($rel_id) { $q = 'SELECT * from allowable_relationship WHERE id = ' . $rel_id; $results = db_query($q); if (mysql_num_rows($results)) { $result = mysql_fetch_assoc($results); $needs_update = false; foreach ($fields as $k => $v) { if ($result[$k] != $v) { $needs_update = true; } } if ($needs_update && $this->mode == 'test') { echo '<p>Would update the allowable relationship ' . $rel_name . '</p>'; } elseif ($needs_update && $this->mode == 'run') { $sqler = new SQLER(); $sqler->update_one('allowable_relationship', $fields, $rel_id); echo '<p>Updated the allowable relationship ' . $rel_name . '</p>'; } else { echo '<p>The ' . $rel_name . ' relationship is up to date. This script has probably been run</p>'; } } } else { echo '<p>The allowable relationship name ' . $rel_name . ' does not exist</p>'; } }
<?php /** * Provides a web service for the Thor WYSIWYG editor to update the temporary XML file in the DB * @package thor */ include_once 'paths.php'; include_once SETTINGS_INC . 'thor_settings.php'; include_once CARL_UTIL_INC . 'dev/prp.php'; include_once CARL_UTIL_INC . 'db/db.php'; include_once CARL_UTIL_INC . 'db/sqler.php'; $tmp_id = $_REQUEST["tmp_id"]; $xml = $_REQUEST["xml"]; connectDB(THOR_FORM_DB_CONN); $sqler = new SQLER(); if (!empty($xml)) { if (!empty($tmp_id)) { $sqler->update_one('thor', array('content' => conditional_stripslashes($xml)), $tmp_id); } else { $sqler->insert('thor', array('content' => conditional_stripslashes($xml))); $tmp_id = mysql_insert_id(); echo $tmp_id; } } else { die('Please provide xml content.'); }
function _get_maintainer_info($maintainer) { // Check to see if it's before or after 7 am, and set the last colleague->ldap sync time appropriately. if (carl_date('G') < 7) { $ldap_last_sync_time = strtotime('7 am yesterday'); } else { $ldap_last_sync_time = strtotime('7 am today'); } /* Either of the following conditions will fire the ldap->reason sync: 1: the cached info predates the last colleague->ldap sync (presumed to be daily by 7 am.) 2: the primary maintainer has been changed since the last ldap->reason sync. */ if ($this->parent->site_info->get_value('cache_last_updated') <= date('Y-m-d', $ldap_last_sync_time) || $this->parent->site_info->get_value('username_cache') != $this->parent->site_info->get_value('primary_maintainer')) { $dir = new directory_service(); if ($dir->search_by_attribute('ds_username', $maintainer, array('ds_email', 'ds_fullname'))) { $email = $dir->get_first_value('ds_email'); $full_name = $dir->get_first_value('ds_fullname'); // lets fall back to the maintainer username if a valid full name is not found for the user $full_name = !carl_empty_html($full_name) ? $full_name : trim(strip_tags($maintainer)); $values = array('email_cache' => $email, 'name_cache' => $full_name, 'cache_last_updated' => date('Y-m-d H:i:s'), 'username_cache' => $maintainer); $update_vals = array('ldap_cache' => $values); reason_include_once('function_libraries/admin_actions.php'); /* I know this is nonstandard, but it's the only way right now to update the entity without creating an archive and changing the last_updated field on all the sites every day... */ $sqler = new SQLER(); foreach ($update_vals as $table => $fields) { $sqler->update_one($table, $fields, $this->parent->site_info->id()); } } } else { $email = $this->parent->site_info->get_value('email_cache'); $full_name = $this->parent->site_info->get_value('name_cache'); } return array('email' => $email, 'full_name' => $full_name); }