function process() { //prep site $this->helper->ensure_type_is_on_site(id_of('publication_type')); $this->helper->ensure_type_is_on_site(id_of('group_type')); $this->helper->ensure_nobody_group_is_on_site(); // gather core information $pub_type_id = id_of('publication_type'); $name = trim(strip_tags($this->get_value('pub_name'))); // populate values array $values['new'] = 0; $values['description'] = trim(get_safer_html($this->get_value('pub_description'))); $values['unique_name'] = trim(strip_tags($this->get_value('pub_unique_name'))); $values['state'] = 'Live'; $values['hold_comments_for_review'] = 'no'; $values['posts_per_page'] = turn_into_int($this->get_value('pub_posts_per_page')); $values['blog_feed_string'] = trim(strip_tags($this->get_value('pub_rss_feed_url'))); $values['publication_type'] = 'Newsletter'; $values['has_issues'] = 'no'; $values['has_sections'] = 'no'; $values['date_format'] = $this->get_value('date_format'); // create the publication $pub_id = reason_create_entity($this->site_id, $pub_type_id, $this->user_id, $name, $values); // associate with nobody posting and commenting groups create_relationship($pub_id, id_of('nobody_group'), relationship_id_of('publication_to_authorized_posting_group')); create_relationship($pub_id, id_of('nobody_group'), relationship_id_of('publication_to_authorized_commenting_group')); }
function create_type($site, $type, $user, $name, $array) { $ret = reason_create_entity($site, $type, $user, $name, $array); id_of('type', false); //clear cache create_default_rels_for_new_type($ret, $array['unique_name']); return $ret; }
function do_updates($mode, $reason_user_id) { if ($mode != 'run' && $mode != 'test') { trigger_error('$mode most be either "run" or "test"'); return; } $messages = array(); $es = new entity_selector(id_of('master_admin')); $es->add_type(id_of('view_type')); $es->add_relation('url = "sections_and_issues.php"'); $es->set_num(1); $view_types = $es->run_one(); if (empty($view_types)) { if ('test' == $mode) { echo '<p>Would have added the view type sections_and_issues.php and the Sections and Issues view</p>' . "\n"; return; } else { $view_type_id = reason_create_entity(id_of('master_admin'), id_of('view_type'), $reason_user_id, 'News Sections and Issues', array('url' => 'sections_and_issues.php')); $view_type = new entity($view_type_id); echo '<p>Added the view type sections_and_issues.php</p>' . "\n"; } } else { echo '<p>sections_and_issues.php view type already added</p>' . "\n"; $view_type = current($view_types); } $es = new entity_selector(id_of('master_admin')); $es->add_type(id_of('view')); $es->add_left_relationship($view_type->id(), relationship_id_of('view_to_view_type')); $es->set_num(1); $views = $es->run_one(); if (empty($views)) { if ('test' == $mode) { echo '<p>Would have added the Sections and Issues view</p>' . "\n"; } else { $es = new entity_selector(id_of('master_admin')); $es->add_type(id_of('field')); $es->add_relation('entity.name = "status"'); $es->set_num(1); $fields = $es->run_one(); $view_id = reason_create_entity(id_of('master_admin'), id_of('view'), $reason_user_id, 'News Sections and Issues', array('display_name' => 'Sections and Issues')); create_relationship($view_id, $view_type->id(), relationship_id_of('view_to_view_type')); create_relationship($view_id, id_of('news'), relationship_id_of('view_to_type')); if (!empty($fields)) { $field = current($fields); create_relationship($view_id, $field->id(), relationship_id_of('view_columns')); create_relationship($view_id, $field->id(), relationship_id_of('view_searchable_fields')); } echo '<p>Added sections and issue view</p>'; } } else { echo '<p>sections and issues view already added.</p>' . "\n"; } }
/** * Run the upgrader * @return string HTML report */ public function run() { if ($this->_link_in_db()) { return 'This script has already run'; } else { if ($id = reason_create_entity(id_of('master_admin'), id_of('admin_link'), $this->user_id(), 'Admin Tools', array('url' => '?cur_module=AdminTools', 'new' => 0))) { if (create_relationship(id_of('master_admin'), $id, relationship_id_of('site_to_admin_link'))) { return 'Created the admin tools link and placed on Master Admin sidebar'; } else { return 'Created the admin tools link but error occurred placing in Master Admin sidebar. You may want to do this manually.'; } } else { return 'Error creating the AdminTools link. You may want to add this link manually, by adding an Admin Link in Master Admin to the URL "?cur_module=AdminTools"'; } } }
function create_image_entity($media_work, $username) { $name = $media_work->get_value('name') . ' (Generated Thumbnail)'; $values = array(); $values['new'] = '0'; $values['description'] = 'A thumbnail image for Vimeo media work ' . $media_work->get_value('name'); $values['no_share'] = '0'; $e = new entity($media_work->get_value('id')); $site_id = $e->get_owner()->id(); if ($username) { return reason_create_entity($site_id, id_of('image'), get_user_id($username), $name, $values); } else { echo date(DATE_RFC822) . ': Empty username. Could not create image entity for Media Work with id ' . $media_work->get_value('id') . '.' . "\n"; } return false; }
/** * Create the google map type. */ protected function create_google_map_type() { // make sure the cache is clear reason_refresh_relationship_names(); reason_refresh_unique_names(); $str = ''; $google_map_id = reason_create_entity(id_of('master_admin'), id_of('type'), $this->user_id(), 'Google Map', $this->google_map_type_details); create_default_rels_for_new_type($google_map_id); create_reason_table('google_map', $this->google_map_type_details['unique_name'], $this->user_id()); $ftet = new FieldToEntityTable('google_map', $this->google_map_table_fields); $ftet->update_entity_table(); ob_start(); $ftet->report(); $str .= ob_get_contents(); ob_end_clean(); // create all the necessary relationships for the google map type create_allowable_relationship(id_of('minisite_page'), id_of('google_map_type'), 'page_to_google_map', $this->page_to_google_map_details); create_allowable_relationship(id_of('event_type'), id_of('google_map_type'), 'event_to_google_map', $this->event_to_google_map_details); $str .= '<p>Created page_to_google_map and even_to_google_map allowable relationships</p>'; return $str; }
function add_quote_type() { if (reason_unique_name_exists('quote_type', false)) { echo '<p>quote_type already exists. No need to create</p>' . "\n"; return false; } if ($this->mode == 'run') { reason_create_entity(id_of('master_admin'), id_of('type'), $this->reason_user_id, 'Quote', $this->quote_type_details); if (reason_unique_name_exists($this->quote_type_details['unique_name'], false)) { $type_id = id_of('quote_type'); create_default_rels_for_new_type($type_id, $this->quote_type_details['unique_name']); $this->add_entity_table_to_type('meta', 'quote_type'); $this->add_entity_table_to_type('chunk', 'quote_type'); // setup its relationship to entity tables echo '<p>quote_types successfully created</p>' . "\n"; } else { echo '<p>Unable to create quote_type</p>'; } } else { echo '<p>Would have created quote_type.</p>' . "\n"; } }
function reason_import($info, $user) { return reason_create_entity($this->admin_page->site_id, id_of('av'), $user->id(), $info['name'], $info); }
function process() { $description = trim(tidy($this->get_value('description'))); $content = trim(get_safer_html(tidy($this->get_value('post_content')))); if(carl_empty_html($description)) { $words = explode(' ', $content, 31); unset($words[count($words)-1]); $description = implode(' ', $words).'…'; $description = trim(tidy($description)); // we're tidying it twice so that if we chop off a closing tag tidy will stitch it back up again } if(!empty($this->user_netID)) { $user_id = make_sure_username_is_user($this->user_netID, $this->site_info->id()); } else { $user_id = $this->site_info->id(); } if($this->hold_posts_for_review) { $status = 'pending'; } else { $status = 'published'; } $values = array ( 'status' => $status, 'release_title' => trim(strip_tags($this->get_value('title'))), 'author' => trim(strip_tags($this->get_value('author'))), 'content' => $content, 'description' => $description, 'datetime' => date('Y-m-d H:i:s', time()), 'keywords' => implode(', ', array(strip_tags($this->get_value('title')), date('Y'), date('F'))), 'show_hide' => 'show', 'new' => 0 ); $this->new_post_id = reason_create_entity( $this->site_info->id(), id_of('news'), $user_id, $values['release_title'], $values ); create_relationship( $this->new_post_id, $this->publication->id(), relationship_id_of('news_to_publication') ); if ($this->successfully_submitted()) { if($this->hold_posts_for_review) { echo '<p>Posts are being held for review on this publication. Please check back later to see if your post has been published.</p>'; echo '<a href="?">Back to main page</a>'; } else { echo '<p>Your post has been published.</p>'; echo '<a href="'.carl_construct_redirect(array('story_id'=>$this->new_post_id)).'">View it.</a>'; } } if($this->get_value('issue')) { create_relationship($this->new_post_id, $this->get_value('issue'), relationship_id_of('news_to_issue')); } if($this->get_value('section')) { create_relationship($this->new_post_id, $this->get_value('section'), relationship_id_of('news_to_news_section')); } if($this->get_value('categories')) { foreach($this->get_value('categories') as $category_id) { // Check to make sure ids posted actually belong to categories in the site if(array_key_exists($category_id, $this->categories)) { create_relationship( $this->new_post_id, $category_id, relationship_id_of('news_to_category') ); } } } $this->show_form = false; $this->do_notifications(); }
echo '<li>Changes required to "no" for news_to_issue</li>'; echo '<li>Changes required to "no" for news_to_news_section</li>'; echo '</ul>'; } if (isset($_POST['verify']) && $_POST['verify'] == 'Run') { //check if nobody group exists $e = id_of('nobody_group'); if ($e) { echo '<p>nobody group already exists - not created</p>'; } else { $user_id = get_user_id($user_netID); $site_id = id_of('master_admin'); $type_id = id_of('group_type'); $name = "Nobody Group"; $values = array('unique_name' => 'nobody_group', 'group_has_members' => 'false'); $new_e_id = reason_create_entity($site_id, $type_id, $user_id, $name, $values, $testmode = false); if (!empty($new_e_id)) { echo '<p>created nobody group entity</p>'; } } //check if blog_type exists - if it does not this database has probably already been upgraded and converted // $test = id_of('blog_type'); $blog_type_exists = empty($test) ? false : true; //echo '<p>There is no type with unique name blog_type, which means '; //echo 'the script cannot continue to run and this database has '; //echo 'probably already been upgraded.</p>'; //die; //check if entity table date_format exists if ($blog_type_exists && create_entity_table("date_format", "blog_type", get_user_id($user_netID))) { echo '<p>created entity table date_format and added to blog type</p>';
$es->set_num(1); $theme_entities = $es->run_one(id_of('theme_type')); if (!empty($theme_entities)) { $theme_entity = current($theme_entities); echo 'Updating ' . $theme_entity->get_value('name') . ' Theme<br />'; reason_update_entity($theme_entity->id(), $user_id, array('name' => 'Simplicity Blue')); } $es = new entity_selector(); $es->add_relation('url = "css/simplicity/green.css"'); $es->set_num(1); $css_entities = $es->run_one(id_of('css')); if (empty($css_entities)) { $css_entity = current($css_entities); echo 'Adding simplicity green theme<br />', "\n"; $css_id = reason_create_entity(id_of('master_admin'), id_of('css'), $user_id, 'Simplicity Green', array('url' => 'css/simplicity/green.css', 'css_relative_to_reason_http_base' => 'true')); $theme_id = reason_create_entity(id_of('master_admin'), id_of('theme_type'), $user_id, 'Simplicity Green', array('unique_name' => 'simplicity_green_theme')); create_relationship($theme_id, $css_id, relationship_id_of('theme_to_external_css_url')); $es = new entity_selector(); $es->add_relation('name = "default"'); $es->set_num(1); $def_temps = $es->run_one(id_of('minisite_template')); if (!empty($def_temps)) { $def_temp = current($def_temps); create_relationship($theme_id, $def_temp->id(), relationship_id_of('theme_to_minisite_template')); } } // Add the css selector to exisiting generic themes (except for core themes) $core_templates = array('tables', 'default'); $core_themes = array('unbranded_theme', 'tableless_2_unbranded_theme', 'unbranded_basic_blue_theme', 'opensource_reason_theme', 'reason_promo', 'reason_promo_subsite', 'simplicity_green_theme'); $css_es = new entity_selector(); $css_es->add_type(id_of('css'));
function process() { if(!empty($this->username)) { $user_id = make_sure_username_is_user($this->username, $this->site_id); } else { $user_id = $this->site_info->id(); } if($this->hold_comments_for_review) { $show_hide = 'hide'; } else { $show_hide = 'show'; } $flat_values = array ( 'state' => 'Live', 'author' => trim(get_safer_html(strip_tags($this->get_value('author')))), 'content' => trim(get_safer_html(strip_tags(tidy($this->get_value('comment_content')), '<p><em><strong><a><ol><ul><li><blockquote><acronym><abbr><br><cite><code><pre>'))), 'datetime' => date('Y-m-d H:i:s'), 'show_hide' => $show_hide, 'new'=>'0', ); $this->comment_id = reason_create_entity( $this->site_id, id_of('comment_type'), $user_id, trim(substr(strip_tags($flat_values['content']),0,40)), $flat_values, $testmode = false ); create_relationship( $this->news_item->_id, $this->comment_id, relationship_id_of('news_to_comment') ); $this->do_notifications(); }
/** * Creates an image entity for the video's thumbnail. * * @param $media_work entity * @param $username string * @return entity */ function create_image_entity($media_work, $username) { $name = $media_work->get_value('name') . ' (Generated Thumbnail)'; $values = array(); $values['new'] = '0'; $values['description'] = 'A placard image for media work ' . $media_work->get_value('name'); $values['no_share'] = '0'; return reason_create_entity($media_work->get_owner()->id(), id_of('image'), get_user_id($username), $name, $values); }
function process() { $site_id = $this->site_id; $counts = array(); for ($i = 1; $i <= $this->max_upload_number; $i++) { $element = $this->get_element('upload_' . $i); if (!empty($element->tmp_full_path) and file_exists($element->tmp_full_path)) { $filename = $this->get_value('upload_' . $i . '_filename'); if ($this->verify_image($element->tmp_full_path)) { if (empty($counts[$filename])) { $this->files[$filename] = $element->tmp_full_path; $counts[$filename] = 1; } else { $counts[$filename]++; $this->files[$filename . '.' . $counts[$filename]] = $element->tmp_full_path; } } else { $this->invalid_files[$filename] = $element->tmp_full_path; } } } if (count($this->files)) { $page_id = (int) $this->get_value('attach_to_page'); $max_sort_order_value = 0; if ($page_id) { $max_sort_order_value = $this->_get_max_sort_order_value($page_id); } $sort_order_value = $max_sort_order_value; $tables = get_entity_tables_by_type(id_of('image')); $valid_file_html = '<ul>' . "\n"; foreach ($this->files as $entry => $cur_name) { $sort_order_value++; $valid_file_html .= '<li><strong>' . $entry . ':</strong> processing '; $date = ''; // get suffix $type = strtolower(substr($cur_name, strrpos($cur_name, '.') + 1)); $ok_types = array('jpg'); // get exif data if ($this->get_value('exif_override') && in_array($type, $ok_types) && function_exists('read_exif_data')) { // read_exif_data() does not obey error supression $exif_data = @read_exif_data($cur_name); if ($exif_data) { // some photos may have different fields filled in for dates - look through these until one is found $valid_dt_fields = array('DateTimeOriginal', 'DateTime', 'DateTimeDigitized'); foreach ($valid_dt_fields as $field) { // once we've found a valid date field, store that and break out of the loop if (!empty($exif_data[$field])) { $date = $exif_data[$field]; break; } } } } else { $date = $this->get_value('datetime'); } $keywords = $entry; if ($this->get_value('keywords')) { $keywords .= ', ' . $this->get_value('keywords'); } // insert entry into DB with proper info $values = array('datetime' => $date, 'image_type' => $type, 'author' => $this->get_value('author'), 'state' => 'Pending', 'keywords' => $keywords, 'description' => $this->get_value('description'), 'name' => $this->get_value('name') ? $this->get_value('name') : $entry, 'content' => $this->get_value('content'), 'original_image_format' => $this->get_value('original_image_format'), 'new' => 0, 'no_share' => $this->get_value('no_share')); //tidy values $no_tidy = array('state', 'new'); foreach ($values as $key => $val) { if (!in_array($key, $no_tidy) && !empty($val)) { $values[$key] = trim(get_safer_html(tidy($val))); } } $id = reason_create_entity($site_id, id_of('image'), $this->user_id, $entry, $values); if ($id) { //assign to categories $categories = $this->get_value('assign_to_categories'); if (!empty($categories)) { foreach ($categories as $category_id) { create_relationship($id, $category_id, relationship_id_of('image_to_category')); } } //assign to gallery page if ($page_id) { create_relationship($page_id, $id, relationship_id_of('minisite_page_to_image'), array('rel_sort_order' => $sort_order_value)); } // resize and move photos $new_name = PHOTOSTOCK . $id . '.' . $type; $orig_name = PHOTOSTOCK . $id . '_orig.' . $type; $tn_name = PHOTOSTOCK . $id . '_tn.' . $type; // Support for new fields; they should be set null by default, but will be // changed below if a thumbnail/original image is created. This is very messy... $thumbnail_image_type = null; $original_image_type = null; // atomic move the file if possible, copy if necessary if (is_writable($cur_name)) { rename($cur_name, $new_name); } else { copy($cur_name, $new_name); } // create a thumbnail if need be list($width, $height, $type, $attr) = getimagesize($new_name); if ($width > REASON_STANDARD_MAX_IMAGE_WIDTH || $height > REASON_STANDARD_MAX_IMAGE_HEIGHT) { copy($new_name, $orig_name); resize_image($new_name, REASON_STANDARD_MAX_IMAGE_WIDTH, REASON_STANDARD_MAX_IMAGE_HEIGHT); $original_image_type = $this->image_types[$type]; } $thumb_dimensions = get_reason_thumbnail_dimensions($site_id); if ($width > $thumb_dimensions['width'] || $height > $thumb_dimensions['height']) { copy($new_name, $tn_name); resize_image($tn_name, $thumb_dimensions['width'], $thumb_dimensions['height']); $thumbnail_image_type = $this->image_types[$type]; } // real original $my_orig_name = $this->add_name_suffix($cur_name, '-unscaled'); if (file_exists($my_orig_name)) { // move the original image into the photostock directory if (is_writable($my_orig_name)) { rename($my_orig_name, $orig_name); } else { copy($my_orig_name, $orig_name); } $original_image_type = $this->image_types[$type]; } $info = getimagesize($new_name); $size = round(filesize($new_name) / 1024); // now we have the size of the resized image. $values = array('width' => $info[0], 'height' => $info[1], 'size' => $size, 'thumbnail_image_type' => $thumbnail_image_type, 'original_image_type' => $original_image_type); // update with new info - don't archive since this is really just an extension of the creation of the item // we needed that ID to do something reason_update_entity($id, $this->user_id, $values, false); $valid_file_html .= 'completed</li>'; } else { trigger_error('Unable to create image entity'); $valid_file_html .= '<li>Unable to import ' . $entry . '</li>'; } sleep(1); } $valid_file_html .= '</ul>' . "\n"; $num_image_string = count($this->files) == 1 ? '1 image has ' : count($this->files) . ' images have '; $valid_file_html .= '<p>' . $num_image_string . 'been successfully imported into Reason.</p>'; $valid_file_html .= '<p>They are now pending.</p>'; $next_steps[] = '<a href="?site_id=' . $site_id . '&type_id=' . id_of('image') . '&user_id=' . $this->user_id . '&cur_module=Lister&state=pending">review & approve imported images</a>'; } if (isset($this->invalid_files)) { $invalid_files = array_keys($this->invalid_files); $invalid_file_html = '<p>The following could not be validated as image files and were not successfully imported.</p>'; $invalid_file_html .= '<ul>'; foreach ($invalid_files as $file) { $invalid_file_html .= '<li><strong>' . reason_htmlspecialchars($file) . '</strong></li>'; } $invalid_file_html .= '</ul>'; } $next_steps[] = '<a href="' . get_current_url() . '">Import another set of images</a>'; if (!isset($this->invalid_files) && !isset($this->files)) { echo '<p>You did not select any files for upload</p>'; } if (isset($valid_file_html)) { echo $valid_file_html; } if (isset($invalid_file_html)) { echo $invalid_file_html; } echo '<p>Next Steps:</p><ul><li>' . implode('</li><li>', $next_steps) . '</li></ul>'; $this->show_form = false; }
protected function build_course_section_entities($data) { echo "Building section entities\n"; foreach ($data as $key => $row) { //echo round(memory_get_usage()/1024,2)."K at point E\n"; $es = new entity_selector(); $es->add_type(id_of('course_section_type')); $name = sprintf('%s %s %s', $row['course_number'], $row['academic_session'], $row['title']); $es->relations = array(); $es->add_relation('sourced_id = "' . $row['sourced_id'] . '"'); if ($result = $es->run_one()) { $section = reset($result); // Find all the values that correspond to the data we're importing $values = array_intersect_key($section->get_values(), $row); if ($values != $row) { echo 'Updating: ' . $name . "\n"; reason_update_entity($section->id(), get_user_id('causal_agent'), $row, false); } else { echo 'Unchanged: ' . $name . "\n"; } } else { if ($this->get_section_parent($row['parent_template_id'])) { echo 'Adding: ' . $name . "\n"; $id = reason_create_entity(id_of('academic_catalog_site'), id_of('course_section_type'), get_user_id('causal_agent'), $name, $row); $section = new entity($id); } else { echo 'No course template found; skipping ' . $name . "\n"; continue; } } if (!empty($section)) { $this->link_section_to_parent($section); } //echo round(memory_get_usage()/1024,2)."K at point D\n"; } }
function add_complete($unique_name,$name,$css = array(),$template_name,$user_id) { if($this->get_id()) { trigger_error('add_complete method may only be called on a reasonTheme that does not yet have an ID assigned.'); return false; } $all_ok = true; $output = '<h4>Adding theme: '.$unique_name.'</h4>'; $output .= '<ol>'; if(empty($template_name)) { $template_name = 'default'; } if(empty($name)) { $name = prettify_string($unique_name); } $template = get_template_by_name($template_name); if(empty($template)) { $all_ok = false; $template_id = reason_add_template($template_name); if(!empty($template_id)) { $template = new entity($template_id); $output .= '<li>Template created ('.$template_name.', id '.$template->id().')</li>'; } else { $output .= '<li>Unable to create template '.$template_name.'. The template file may not be placed correctly.'; if($this->test_mode) { $output .= ' Would abort theme addition.'; } else { $output .= ' Aborting theme addition.'; } $output .= '</li></ol>'; return array('success'=>false,'report'=>$output); } } else { $output .= '<li>Template found ('.$template_name.', id '.$template->id().')</li>'; } $theme_id = id_of($unique_name); if(!$theme_id) { $all_ok = false; $output .= '<li>Theme with unique name '.$unique_name.' needs to be created</li>'; if(!$this->test_mode) { $theme_id = $this->create($unique_name,$name,$template->id(),$user_id); if(!$theme_id) { $output .= '<li>Theme '.$name.' unable to be created; aborting theme addition</li></ol>'; return array('success'=>false,'report'=>$output); } else { $output .= '<li>Theme with unique name '.$unique_name.' created</li>'; } } else { $output .= '<li>Would have attempted to create theme entity.</li>'; } } else { $this->set_id($theme_id); } if($this->get_template_id() != $template->id()) { $all_ok = false; $output .= '<li>Current theme template id ('.$this->get_template_id().') not the same as specified in update ('.$template->id().').</li>'; if($this->test_mode) { $output .= '<li>Would have set theme template to be id '.$template->id().'</li>'; } else { if($this->attach_template($template->id())) { $output .= '<li>Attached template id '.$template->id().' to '.$unique_name.'.</li>'; } else { $output .= '<li>Unable to attach template for some reason. Aborting theme addition.</li>'; return array('success'=>false,'report'=>$output); } } } $retrieved_css_entities = array(); foreach($css as $css_name=>$css_info) { $output .= '<li>CSS: '.$css_name.'<ol>'; if(empty($css_info['url'])) { $output .= '<li>'.$css_name.' has no url specified; skipping this css item</li></ol></li>'; continue; } else { $css_url = $css_info['url']; } if(empty($retrieved_css_entities[$css_url])) { $es = new entity_selector(); $es->add_type(id_of('css')); $es->add_relation('url = "'.addslashes($css_url).'"'); $es->set_num(1); $css_ents = $es->run_one(); if(!empty($css_ents)) { $retrieved_css_entities[$css_url] = current($css_ents); } } if(empty($retrieved_css_entities[$css_url])) { $all_ok = false; //create css & get id of css if($this->test_mode) { $output .= '<li>Would have created a css entity for '.$css_url.' and attached it to the theme</li>'; } else { $css_id = reason_create_entity(id_of('master_admin'), id_of('css'), $user_id, $css_name, $css_info); if($css_id) { $output .= '<li>Created a css entity for '.$css_url.'</li>'; } else { $output .= '<li>Tried to create a css entity for '.$css_url.' but was unsuccessful. Aborting creation of this css item.</li>'; continue; } } } else { $css_id = $retrieved_css_entities[$css_url]->id(); $output .= '<li>A css entity exists for '.$css_url.' at Reason id '.$css_id.'</li>'; } if(!empty($css_id)) { // attach css $attached_css = $this->get_css(); if(empty($attached_css[$css_id])) { $all_ok = false; if($this->test_mode) { $output .= '<li>Would have attached css at '.$css_url.' to '.$unique_name.'.</li>'; } else { if($this->attach_css($css_id)) { $output .= '<li>Attached css at '.$css_url.' to '.$unique_name.'.</li>'; } else { $output .= '<li>Unable to attach css at '.$css_url.' to '.$unique_name.'; perhaps there is an unknown problem.</li>'; } } } else { $output .= '<li>Css at '.$css_url.' already attached to '.$unique_name.'</li>'; } $output .= '</ol></li>'; } } if($all_ok) { $output .= '<li><strong>Everything OK.</strong> The theme '.$unique_name.' appears to be set up correctly. No database changes are needed.</li>'; } $output .= '</ol>'; return array('success'=>true,'report'=>$output); }
/** * Called in the Zencoder notification receiver after the Reason entity has been created. * This hooks up the original mp3 or ogg file to a Reason entity, if needed. * * @param $filepath string * @param $media_work entity * @param $num_outputs int * @param $shim obj * @param $netid string */ public static function post_process_audio($filepath, $media_work, $num_outputs, $shim, $netid) { // We need to create a media file for the source mp3 or ogg file if ($num_outputs == 2) { $filename = end(explode('/', $filepath)); $extension = end(explode('.', $filename)); if ($extension == 'mp3') { $mime_type = 'audio/mpeg'; } elseif ($extension == 'ogg') { $mime_type = 'audio/ogg'; } else { trigger_error('Invalid extension: ' . $extension); } $path = self::get_path(false, $filename, $media_work, 'original'); $base_url = self::get_base_url(); $client = self::_get_client(); if (!$client) { trigger_error('Could not create S3 object.'); return; } $web_url = $base_url . $path; $obj_info_arr = $client->getObjectInfo(S3_BUCKET_NAME, $path); $filesize = $obj_info_arr['size']; $name = basename($web_url); $web_url = str_replace($name, urlencode($name), $web_url); $values = array('av_type' => 'Audio', 'flavor_id' => 'original', 'media_format' => 'HTML5', 'url' => $web_url, 'download_url' => $web_url, 'mime_type' => $mime_type, 'media_size_in_bytes' => $filesize, 'media_size' => format_bytes_as_human_readable($filesize), 'media_quality' => $shim->_get_bitrate($filepath) . ' kbps', 'media_duration' => $shim->_get_duration($filepath)); $media_file_id = reason_create_entity($media_work->get_owner()->id(), id_of('av_file'), get_user_id($netid), $media_work->get_value('name') . ' ' . $extension, $values); create_relationship($media_work->id(), $media_file_id, relationship_id_of('av_to_av_file')); } }
protected function _create_media_entity($disco) { // put together the values for the entity $name = htmlspecialchars($disco->get_value('media_title')); $values = $this->params['default_values']; $values['name'] = $name; $values['new'] = "0"; $values['author'] = htmlspecialchars($disco->get_value('name')); if ($disco->get_value('class_year')) { switch (strlen($disco->get_value('class_year'))) { case 4: $values['author'] .= ' \'' . htmlspecialchars(mb_substr($disco->get_value('class_year'), -2)); break; case 3: $values['author'] .= htmlspecialchars($disco->get_value('class_year')); break; case 2: $values['author'] .= ' \'' . htmlspecialchars($disco->get_value('class_year')); } } $values['description'] = htmlspecialchars($disco->get_value('description')); $values['keywords'] = $name . ', ' . $values['author']; $values['entry_id'] = $this->_entry->id; $values['av_type'] = $disco->get_value('av_type'); $values['transcoding_status'] = 'converting'; $values['integration_library'] = 'kaltura'; $values['tmp_file_name'] = $this->_filename; // create the entity $this->_media_work_id = $id = reason_create_entity($this->site_id, id_of('av'), $this->_user_id, $name, $values); //$this->set_form_id($id); $page_id = $this->page_id; if (!empty($this->params['entries_gallery_page'])) { if (reason_unique_name_exists($this->params['entries_gallery_page'])) { $page_id = id_of($this->params['entries_gallery_page']); } else { trigger_error('Unable to find uniquely named page ' . $this->params['entries_gallery_page'] . '. Attaching photos to form page.'); } } create_relationship($page_id, $id, relationship_id_of('minisite_page_to_av')); // access restriction $da = reason_get_default_access(); if ($this->params['default_group_uname'] && reason_unique_name_exists($this->params['default_group_uname'])) { $group_id = id_of($this->params['default_group_uname']); create_relationship($id, $group_id, relationship_id_of('av_restricted_to_group')); } elseif ($group_id = $da->get($this->site_id, 'av', 'av_restricted_to_group')) { create_relationship($id, $group_id, relationship_id_of('av_restricted_to_group')); } return $id; }
function create_image_entity() { $name = $this->media_work->get_value('name') . ' (Generated Thumbnail)'; $values = array(); $values['new'] = '0'; $values['author'] = $this->user->get_value('name'); $values['description'] = 'A placard image for media work ' . $this->media_work->get_value('name'); $values['no_share'] = '0'; return reason_create_entity($this->admin_page->site_id, id_of('image'), $this->user->id(), $name, $values); }
/** * Creates a media file whose url is a file that doesn't need to go through Zencoder because * it's either an mp3 or ogg. * @param $filepath string * @param $media_work entity = * @param $user_id int */ public static function create_audio_source_file($filepath, $media_work, $user_id) { $filename = basename($filepath); $extension = end(explode('.', $filename)); if ($extension == 'mp3') { $mime_type = 'audio/mpeg'; } else { $mime_type = 'audio/ogg'; } $needs_deleting = false; if (strpos($filepath, 'http://') !== 0 && strpos($filepath, 'https://') !== 0) { $base_path = str_replace($filename, '', $filepath); $filepath = $base_path . $filename; $filesize = filesize($filepath); } $media_file_id = reason_create_entity($media_work->get_owner()->id(), id_of('av_file'), $user_id, $media_work->get_value('name') . ' ' . $extension, array('av_type' => 'Audio', 'flavor_id' => 'original')); create_relationship($media_work->id(), $media_file_id, relationship_id_of('av_to_av_file')); $web_url = self::get_storage_class()->store_media($media_file_id, $filepath, '', $media_work, 'original'); $values = array('media_format' => 'HTML5', 'url' => $web_url, 'download_url' => $web_url, 'mime_type' => $mime_type, 'media_size_in_bytes' => $filesize, 'media_size' => format_bytes_as_human_readable($filesize), 'media_quality' => self::_get_bitrate($filepath) . ' kbps', 'media_duration' => self::_get_duration($filepath)); reason_update_entity($media_file_id, $media_work->get_owner()->id(), $values, false); }
function create_image_entity($username) { $name = $this->manager->get_value('name') . ' (Generated Thumbnail)'; $values = array(); $values['new'] = '0'; $values['description'] = 'A thumbnail image for Vimeo media work ' . $this->manager->get_value('name'); $values['no_share'] = '0'; $e = new entity($this->manager->get_value('id')); $site_id = $e->get_owner()->id(); if ($username) { return reason_create_entity($site_id, id_of('image'), get_user_id($username), $name, $values); } return false; }
function add_editor_user_role($test_mode = true) { echo '<h3>Adding editor user role</h3>'; $editor_user_role_id = id_of('editor_user_role'); echo '<ul>'; if (!empty($editor_user_role_id)) { echo '<li>Editor user role already exists; no need to create it</li>'; } else { if ($test_mode) { echo '<li>Would have created editor user role</li>'; } else { $editor_user_role_id = reason_create_entity(id_of('master_admin'), id_of('user_role'), $GLOBALS['__cur_user_id_hack__'], 'Editor', array('new' => '0', 'unique_name' => 'editor_user_role')); if ($editor_user_role_id) { echo '<li>Created editor user role (ID: ' . $editor_user_role_id . ')</li>'; } else { echo '<li>Unable to create editor user role! Aborting this step.</li></ul>'; return false; } } } // get users with their user roles $es = new entity_selector(); $es->add_type(id_of('user')); $es->add_left_relationship_field('user_to_user_role', 'entity', 'id', 'user_role_id', false); $users = $es->run_one(); if ($test_mode) { echo '<li>Would have added editor user role to these users currently without a role:'; } else { echo '<li>Adding editor user role to users currently without a role:'; } echo '<ol>'; $count = 0; foreach ($users as $user) { if (!$user->get_value('user_role_id')) { $count++; if ($test_mode) { echo '<li>' . $user->get_value('name') . '</li>'; } else { if (create_relationship($user->id(), $editor_user_role_id, relationship_id_of('user_to_user_role'))) { echo '<li>' . $user->get_value('name') . '</li>'; } else { echo '<li><strong>Eeep!</strong> Problem assigning editor user role to ' . $user->get_value('name') . '</li>'; } } } } echo '</ol>'; if (!$count) { echo '<strong>No users needed to be updated; all users have roles.</strong>'; } echo '</li>'; echo '</ul>'; }
protected function create_social_account_type() { $str = ''; $social_account_type_id = reason_create_entity(id_of('master_admin'), id_of('type'), $this->user_id(), 'Social Account', $this->social_account_type_details); $str .= '<p>Create social account type entity</p>'; create_default_rels_for_new_type($social_account_type_id); create_reason_table('social_account', $this->social_account_type_details['unique_name'], $this->user_id()); $ftet = new FieldToEntityTable('social_account', array('account_type' => array('db_type' => 'tinytext'), 'account_id' => array('db_type' => 'tinytext'), 'account_details' => array('db_type' => 'text'))); $ftet->update_entity_table(); ob_start(); $ftet->report(); $str .= ob_get_contents(); ob_end_clean(); create_allowable_relationship(id_of('site'), id_of('social_account_type'), 'site_to_social_account', $this->site_to_social_account_details); $str .= '<p>Created site to social account relationship.</p>'; create_relationship(id_of('master_admin'), id_of('social_account_type'), relationship_id_of('site_to_type')); return $str; }
function _add_bedrich_theme() { $theme_id = id_of('bedrich_theme'); $created_theme = false; $created_template = false; $created_css = false; if (empty($theme_id)) { if ($this->_testmode) { $this->_report[] = 'Would have created the Bedrich theme'; } else { $theme_id = reason_create_entity(id_of('master_admin'), id_of('theme_type'), $this->_user_id, 'Bedrich', array('unique_name' => 'bedrich_theme')); $this->_report[] = 'Created the Bedrich theme (id: ' . $theme_id . ')'; $created_theme = true; } } else { $this->_report[] = 'Bedrich theme exists. No need to create it.'; } $es = new entity_selector(id_of('master_admin')); $es->add_type(id_of('minisite_template')); $es->add_relation('entity.name = "bedrich"'); $es->set_num(1); $templates = $es->run_one(); if (empty($templates)) { if ($this->_testmode) { $this->_report[] = 'Would have created the Bedrich template'; } else { $template_id = reason_create_entity(id_of('master_admin'), id_of('minisite_template'), $this->_user_id, 'bedrich'); $this->_report[] = 'Created the Bedrich template (id: ' . $template_id . ')'; $created_template = true; } } else { $template = current($templates); $template_id = $template->id(); $this->_report[] = 'bedrich template exists. No need to create it.'; } $es = new entity_selector(id_of('master_admin')); $es->add_type(id_of('css')); $es->add_relation('url = "css/bedrich/bedrich.css"'); $es->set_num(1); $css = $es->run_one(); if (empty($css)) { if ($this->_testmode) { $this->_report[] = 'Would have created the Bedrich css'; } else { $css_id = reason_create_entity(id_of('master_admin'), id_of('css'), $this->_user_id, 'bedrich', array('url' => 'css/bedrich/bedrich.css', 'css_relative_to_reason_http_base' => 'true')); $this->_report[] = 'Created the Bedrich css (id: ' . $css_id . ')'; $created_css = true; } } else { $c = current($css); $css_id = $c->id(); $this->_report[] = 'bedrich css exists. No need to create it.'; } if (!empty($theme_id)) { $theme = new entity($theme_id); if (!empty($css_id) && !$theme->get_left_relationship('theme_to_external_css_url')) { create_relationship($theme_id, $css_id, relationship_id_of('theme_to_external_css_url')); $this->_report[] = 'attached bedrich css to bedrich theme'; } else { $this->_report[] = 'bedrich theme already attached to css. No need to attach css.'; } if (!empty($template_id) && !$theme->get_left_relationship('theme_to_minisite_template')) { create_relationship($theme_id, $template_id, relationship_id_of('theme_to_minisite_template')); $this->_report[] = 'attached bedrich template to bedrich theme'; } else { $this->_report[] = 'berich theme already attached to template. No need to attach template.'; } } }
/** * Move all the fields of one table into another table for a specific type * * This method is for denormalizing Reason tables. For example, a type may use a common table * like meta, datetime, or chunk. For performance reasons, it can be desirable to collapse * these tables into a single table just for that type. This method will do that. * * @param integer $type The ID of the type whose fields we are moving * @param string $source_table The name of the table we are moving fields FROM * @param string $destination_table The name of the table we are moving fields TO * @param integer $user_id The Reason ID of the user who is doing this move * @return boolean Success * * @todo Add limit to ensure fields are only created that don't already exist */ function reason_move_table_fields($type, $source_table, $destination_table, $user_id) { // Sanity checks if(empty($type)) { trigger_error('No type provided in reason_move_table_fields()'); return false; } if(empty($source_table)) { trigger_error('No source table provided in reason_move_table_fields()'); return false; } if(!is_string($source_table)) { trigger_error('Source table provided not a string in reason_move_table_fields()'); return false; } if(empty($destination_table)) { trigger_error('No destination table provided in reason_move_table_fields()'); return false; } if(!is_string($destination_table)) { trigger_error('Destination table provided not a string in reason_move_table_fields()'); return false; } if('entity' == $source_table || 'entity' == $destination_table) { trigger_error('reason_move_table_fields() cannot move fields into or out of the entity table.'); return false; } if(is_object($type)) { $type_id = $type->id(); } elseif(is_numeric($type)) { $type_id = (integer) $type; } else { $type_id = id_of($type); } if(empty($type_id)) { trigger_error('Invalid type specified in reason_move_table_fields().'); return false; } if(is_object($type)) $type_entity = $type; else $type_entity = new entity($type_id); $type_vals = $type_entity->get_values(); if(empty($type_vals)) { trigger_error('Type specified (id '.$type_id.') is not a Reason entity in reason_move_table_fields().'); return false; } if($type_entity->get_value('type') != id_of('type')) { trigger_error('Type specified (id '.$type_id.') is not a Type entity in reason_move_table_fields().'); return false; } if($type_entity->get_value('state') != 'Live') { trigger_error('Type specified (id '.$type_id.') is not a live entity in reason_move_table_fields().'); return false; } if(empty($user_id)) { trigger_error('No user id specified in reason_move_table_fields().'); return false; } $user = new entity($user_id); if(!$user->get_values() || $user->get_value('type') != id_of('user')) { trigger_error('Invalid user ID specified in reason_move_table_fields().'); return false; } // check for table existence $es = new entity_selector(); $es->add_type(id_of('content_table')); $es->add_relation('`name` = "'.addslashes($source_table).'"'); $source_table_result = $es->run_one(); if(empty($source_table_result)) { trigger_error('Source table "'.$source_table.'" does not exist in reason_move_table_fields()'); return false; } $es = new entity_selector(); $es->add_type(id_of('content_table')); $es->add_relation('`name` = "'.addslashes($destination_table).'"'); $destination_table_result = $es->run_one(); if(empty($destination_table_result)) { trigger_error('Destination table "'.$destination_table.'" does not exist in reason_move_table_fields()'); return false; } $source_table_entity = current($source_table_result); $destination_table_entity = current($destination_table_result); // ensure type uses both tables $type_tables = get_entity_tables_by_type( $type_id ); if(!in_array($source_table, $type_tables)) { trigger_error('Source table "'.$source_table.'" not part of the type in reason_move_table_fields()'); return false; } if(!in_array($destination_table, $type_tables)) { trigger_error('Destination table "'.$destination_table.'" not part of the type in reason_move_table_fields()'); return false; } $es = new entity_selector(); $es->add_type(id_of('type')); $es->add_left_relationship($destination_table_entity->id(),relationship_id_of('type_to_table')); $es->add_relation('`entity`.`id` != "'.addslashes($type_id).'"'); $other_types = $es->run_one(); if(!empty($other_types)) { trigger_error(count($other_types).' other type(s) share the destination table with the type specified in reason_move_table_fields(). reason_move_table_fields() can only move fields into single-type tables.'); return false; } // get the fields in the old table $es = new entity_selector(); $es->add_type(id_of('field')); $es->add_left_relationship($source_table_entity->id(), relationship_id_of('field_to_entity_table')); $source_table_fields = $es->run_one(); if(empty($source_table_fields)) { trigger_error('Source table '.$source_table.' does not appear to have any fields associated with it in Reason. Unable to move its content in reason_move_table_fields()'); } $q = 'DESCRIBE `'.addslashes($destination_table).'`'; $handle = db_query( $q, 'Unable to describe destination table in reason_move_table_fields()' ); $raw_dest_cols = array(); while($row = mysql_fetch_assoc($handle)) { $raw_dest_cols[] = $row['Field']; } foreach($source_table_fields as $k=>$field) { if(in_array($field->get_value('name'),$raw_dest_cols)) { trigger_error($field->get_value('name').' field is already in destination table. Unable to accomplish reason_move_table_fields().'); return false; } $tmp_field_name = $field->get_value('name').'_move_tmp'; if(in_array($tmp_field_name,$raw_dest_cols)) { trigger_error($tmp_field_name.' field already in destination table. There appears to have been an error in a previous attempt to run reason_move_table_fields(). Please drop this column in MySQL and try again.'); return false; } $source_table_fields[$k]->set_value('_field_move_temp_name',$field->get_value('name').'_move_tmp'); } // Done with sanity checks // map old to temp field names & create new fields $query_parts = array(); foreach($source_table_fields as $k=>$field) { $source_table_fields[$k]->set_value('_field_move_temp_name',$field->get_value('name').'_move_tmp'); $q = 'ALTER TABLE `'.addslashes($destination_table).'` ADD '.addslashes( $field->get_value('_field_move_temp_name') ).' '. $field->get_value('db_type'); db_query( $q, 'Unable to create new field '.$field->get_value('_field_move_temp_name').' in reason_move_table_fields()' ); $values = array(); foreach($field->get_values() as $f=>$v) { if($f != 'name' && $f != 'id' && strpos($f,'_') !== 0) { $values[$f] = $v; } } $id = reason_create_entity( id_of('master_admin'), id_of('field'), $user_id, $field->get_value('_field_move_temp_name'), $values); $source_table_fields[$k]->set_value('_new_field_id',$id); $query_parts[] = '`'.addslashes($destination_table).'`.`'.addslashes($field->get_value('_field_move_temp_name')).'` = `'.addslashes($source_table).'`.`'.addslashes($field->get_value('name')).'`'; } // copy content of old fields to new fields $q = 'UPDATE `'.addslashes($destination_table).'`, `'.addslashes($source_table).'`, `entity` SET '.implode(' , ',$query_parts).' WHERE `'.addslashes($destination_table).'`.`id` = `'.addslashes($source_table).'`.`id` AND `'.addslashes($destination_table).'`.`id` = `entity`.`id` AND `entity`.`type` = "'.addslashes($type_id).'";'; db_query($q,'Attempt to move data between fields'); // zap source table's type-to-table relationship for this type $conditions = array( 'entity_a' => $type_id, 'entity_b' => $source_table_entity->id(), 'type' => relationship_id_of('type_to_table'), ); delete_relationships( $conditions ); // create new field-to-table relationship for new fields and update field names in new table -- remove temp flag foreach($source_table_fields as $field) { create_relationship( $field->get_value('_new_field_id'), $destination_table_entity->id(), relationship_id_of( 'field_to_entity_table' ) ); $q = 'ALTER TABLE `'.addslashes($destination_table).'` CHANGE '.addslashes($field->get_value('_field_move_temp_name')).' '.addslashes( $field->get_value('name') ).' '.$field->get_value('db_type') ; db_query( $q, 'Unable to change field name of '.$field->get_value('_field_move_temp_name').' in reason_move_table_fields()' ); reason_update_entity( $field->get_value('_new_field_id'), $user_id, array('name' => $field->get_value('name') ), false ); } // delete the rows from the source table $q = 'DELETE `'.addslashes($source_table).'` FROM `'.addslashes($source_table).'`, `entity` WHERE `'.addslashes($source_table).'`.`id` = `entity`.`id` AND `entity`.`type` = "'.addslashes($type_id).'"'; db_query($q,'Attempt to delete rows from '.$source_table.' in reason_move_table_fields()'); get_entity_tables_by_id( $type_id, false ); return true; }
function reason_import($info, $entry, $user) { $info['entry_id'] = $entry->id; return reason_create_entity($this->admin_page->site_id, id_of('av'), $user->id(), $info['name'], $info); // todo: categories }
function update_default_issue_view() { $es = new entity_selector(id_of('master_admin')); $es->add_type(id_of('view')); $es->add_right_relationship(id_of('issue_type'), relationship_id_of('type_to_default_view')); $es->set_num(1); $views = $es->run_one(); if (!empty($views)) { echo '<p>Default issue view already exists. No need to create a default issue view.</p>' . "\n"; return; } if ($this->mode == 'run') { echo '<p>Creating default issue view...</p>' . "\n"; echo '<ul>' . "\n"; $id = reason_create_entity(id_of('master_admin'), id_of('view'), $this->reason_user_id, 'Default Issue View', array('display_name' => 'List', 'column_order' => 'id, name, datetime, show_hide, last_modified', 'default_sort' => 'datetime, desc')); if (empty($id)) { echo '<li>Unable to create default issue view. This is not a critical update, but you may want to look into why this did not work. Aborting default issue creation.</li></ul>' . "\n"; return; } echo '<li>Created default issue view</li>' . "\n"; $success = create_relationship($id, id_of('generic_lister'), relationship_id_of('view_to_view_type')); if ($success) { echo '<li>Associated default issue view with the List view type.</li>' . "\n"; } else { echo '<li>Did not successfully associate default issue view with the List view type.</li>' . "\n"; } $show_hide_field_id = $this->get_field_id('show_hide', 'show_hide'); if (!empty($show_hide_field_id)) { $success = create_relationship($id, $show_hide_field_id, relationship_id_of('view_columns')); if ($success) { echo '<li>Added the show_hide field to the view.</li>' . "\n"; } else { echo '<li>Did not successfully add the show_hide field to the view.</li>' . "\n"; } $success = create_relationship($id, $show_hide_field_id, relationship_id_of('view_searchable_fields')); if ($success) { echo '<li>Added the show_hide field to the searchable fields.</li>' . "\n"; } else { echo '<li>Did not successfully add the show_hide field to the searchable fields.</li>' . "\n"; } } $datetime_field_id = $this->get_field_id('dated', 'datetime'); if (!empty($datetime_field_id)) { $success = create_relationship($id, $datetime_field_id, relationship_id_of('view_columns')); if ($success) { echo '<li>Added the datetime field to the view.</li>' . "\n"; } else { echo '<li>Did not successfully add the datetime field to the view.</li>' . "\n"; } $success = create_relationship($id, $datetime_field_id, relationship_id_of('view_searchable_fields')); if ($success) { echo '<li>Added the datetime field to the searchable fields.</li>' . "\n"; } else { echo '<li>Did not successfully add the datetime field to the searchable fields.</li>' . "\n"; } } $success = create_relationship(id_of('issue_type'), $id, relationship_id_of('type_to_default_view')); if ($success) { echo '<li>Set up new view as the default view for issues.</li>' . "\n"; } else { echo '<li>Did not successfully set up new view as the default view for issues.</li>' . "\n"; } echo '</ul>' . "\n"; } else { echo '<p>Would have created the default issue view.</p>' . "\n"; } }
private function create_view() { return reason_create_entity(id_of('master_admin'), id_of('view'), $this->user_id(), 'List View with Duplicate', array('new' => 0)); }
protected function create_course_section_type() { $str = ''; $course_section_type_id = reason_create_entity(id_of('master_admin'), id_of('type'), $this->user_id(), 'Course Section', $this->course_section_type_details); $str .= '<p>Create course section type entity</p>'; create_default_rels_for_new_type($course_section_type_id); create_reason_table('course_section', $this->course_section_type_details['unique_name'], $this->user_id()); $ftet = new FieldToEntityTable('course_section', $this->course_section_type_schema); $ftet->update_entity_table(); ob_start(); $ftet->report(); $str .= ob_get_contents(); ob_end_clean(); //create_relationship( id_of('master_admin'), id_of('social_account_type'), relationship_id_of('site_to_type') ); return $str; }
reason_include_once('classes/amputee_fixer.php'); $fields = array('directory_service_value' => array('db_type' => 'tinytext'), 'directory_service' => array('db_type' => 'tinytext'), 'audience_filter' => array('db_type' => 'tinytext')); $updater = new FieldToEntityTable('audience_integration', $fields); $updater->update_entity_table(); $updater->report(); $fixer = new AmputeeFixer(); $fixer->fix_amputees($audience_type_id); $fixer->generate_report(); } } $audience_ids = array(); foreach ($audiences as $audience => $audience_data) { $out[] = 'Looking at audience: ' . $audience; if (!id_of($audience . '_audience')) { $out[] = $audience . ' entity does not exist yet'; $audience_ids[$audience] = reason_create_entity(id_of('master_admin'), $audience_type_id, get_user_id('root'), $audience_data['name'], $audience_data); $out[] = 'Created ' . $audience . ' entity'; } else { $out[] = $audience . ' exists'; reason_update_entity(id_of($audience . '_audience'), get_user_id('root'), $audience_data); $audience_ids[$audience] = id_of($audience . '_audience'); $out[] = 'Updated ' . $audience . ' entity'; } } // figure out which types use the audience table $types = get_types_with_audience_table(); // create an allowable relationship for each one foreach ($types as $type) { $out[] = $type->get_value('name') . ' uses the audience table'; $rel_name = str_replace(' ', '_', strtolower($type->get_value('name'))) . '_to_audience'; $alrel_id = relationship_id_of($rel_name);