/**
  * @return boolean
  */
 protected function _add_dynamic_site_id_option()
 {
     $entity_table_name = 'admin_link';
     $fields = array('add_dynamic_site_id' => array('db_type' => "enum('true','false')"));
     $updater = new FieldToEntityTable($entity_table_name, $fields);
     $result = $updater->update_entity_table();
     $updater->report();
     return $result;
 }
 /**
  * Run the upgrader
  *
  * @return string HTML report
  */
 public function run()
 {
     $entity_table_name = 'form';
     $updater = new FieldToEntityTable($entity_table_name, $this->get_fields_definition());
     if ($updater->field_exists('apply_akismet_filter')) {
         return '<p>This updater has already been run.</p>';
     } else {
         $updater->update_entity_table();
         ob_start();
         $updater->report();
         return ob_get_clean();
     }
 }
 /**
  * Run the upgrader
  *
  * @return string HTML report
  */
 public function run()
 {
     $entity_table_name = 'page_node';
     $fields = array('extra_head_content_structured' => array('db_type' => 'text'));
     $updater = new FieldToEntityTable($entity_table_name, $fields);
     if ($updater->field_exists('extra_head_content_structured')) {
         return '<p>This updater has already been run.</p>';
     } else {
         $updater->update_entity_table();
         ob_start();
         $updater->report();
         return ob_get_clean();
     }
 }
 protected function add_fields($test_mode = false)
 {
     $log = '';
     foreach ($this->new_fields as $field => $db_type) {
         $field_params = array($field => array('db_type' => $db_type));
         $updater = new FieldToEntityTable('page_node', $field_params);
         $updater->test_mode = $test_mode;
         $updater->update_entity_table();
         ob_start();
         $updater->report();
         $log .= ob_get_contents();
         ob_end_clean();
     }
     return $log;
 }
 /**
  * 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;
 }
 /**
  * Run the upgrader
  * @return string HTML report
  */
 public function run()
 {
     if ($this->already_run()) {
         return '<p>This script has already run.</p>';
     } else {
         $ret = '';
         if (!$this->site_changes_made()) {
             $updater = new FieldToEntityTable('site', array('theme_customization' => array('db_type' => 'text')));
             $updater->update_entity_table();
             ob_start();
             $updater->report();
             $ret .= ob_get_flush();
         }
         if (!$this->theme_changes_made()) {
             $table_id = create_reason_table('theme', 'theme_type', $this->user_id());
             $updater = new FieldToEntityTable('theme', array('theme_customizer' => array('db_type' => 'tinytext')));
             $updater->update_entity_table();
             ob_start();
             $updater->report();
             $ret .= ob_get_flush();
         }
         return $ret;
     }
 }
 /**
  * Run the upgrader
  *
  * @return string HTML report
  */
 public function run()
 {
     $entity_table_name = 'blog';
     $updater = new FieldToEntityTable($entity_table_name, $this->get_fields_definition());
     if ($updater->field_exists('blog_feed_include_content') && $updater->field_exists('reminder_days') && $updater->field_exists('reminder_emails')) {
         return '<p>This updater has already been run.</p>';
     } else {
         $updater->update_entity_table();
         ob_start();
         $updater->report();
         return ob_get_clean();
     }
 }
 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;
 }
        $es->add_relation('entity.name IN ("use_custom_footer","custom_footer")');
        $es->add_left_relationship($table->id(), relationship_id_of('field_to_entity_table'));
        $es->set_num(2);
        $fields = $es->run_one();
        $fields_to_create = array('use_custom_footer' => 'enum(\'yes\',\'no\')', 'custom_footer' => 'text');
        foreach ($fields as $field) {
            unset($fields_to_create[$field->get_value('name')]);
        }
        if (empty($fields_to_create)) {
            echo '<p>Fields exist; script has already been run.</p>';
        } else {
            if ($_POST['go'] != 'run') {
                echo '<p>Would have created these fields:</p>';
                pray($fields_to_create);
            } else {
                $update_fields = array();
                foreach ($fields_to_create as $key => $value) {
                    $update_fields[$key] = array('db_type' => $value);
                }
                $updater = new FieldToEntityTable('site', $update_fields);
                $updater->update_entity_table();
                $updater->report();
            }
        }
    }
}
?>
<p><a href="index.php">Return to Index</a></p>
</body>
</html>
 protected function create_publication_social_sharing_field()
 {
     $ftet = new FieldToEntityTable('blog', array('enable_social_sharing' => array('db_type' => "enum('yes','no')")));
     $ftet->update_entity_table();
     ob_start();
     $ftet->report();
     $str = ob_get_contents();
     ob_end_clean();
     return $str;
 }
 /**
  * Creates entity tables if necessary
  */
 function add_field_to_entity_table($table, $field_name, $field_db_type)
 {
     // lets make sure the table exists first
     $es = new entity_selector();
     $es->add_type(id_of('content_table'));
     $es->add_relation('entity.name = "' . $table . '"');
     $results = $es->run_one();
     if ($results) {
         if (in_array($field_name, get_fields_by_content_table($table))) {
             echo '<p>The ' . $table . ' entity table already has the field ' . $field_name . ' - the script has probably been run.</p>';
             return false;
         } else {
             $updater = new FieldToEntityTable($table, array($field_name => array('db_type' => $field_db_type)));
             if ($this->mode == 'test') {
                 $updater->test_mode = true;
             }
             $updater->update_entity_table();
             $updater->report();
         }
     }
 }
 /**
  * Checks if image table has our new fields (thumbnail_image_type and original_image_type) --
  * if not, then creates these fields in the image table
  * 
  * @return boolean whether or not new fields were actually created
  */
 function add_unexisting_image_fields()
 {
     $table_name = 'image';
     $new_field_names = array('thumbnail_image_type' => array('db_type' => 'tinytext'), 'original_image_type' => array('db_type' => 'tinytext'));
     $existing_field_names = get_fields_by_content_table($table_name);
     // check if our new fields exist yet
     $new_fields_needed = false;
     foreach (array_keys($new_field_names) as $field_name) {
         if (!in_array($field_name, $existing_field_names)) {
             $new_fields_needed = true;
         }
     }
     if ($new_fields_needed) {
         $field_updater = new FieldToEntityTable($table_name, $new_field_names);
         $field_updater->update_entity_table();
         $field_updater->report();
         return true;
     } else {
         return false;
     }
 }
 protected function add_transcoding_status_field($test_mode = false)
 {
     $log = '';
     $field_params = array('transcoding_status' => array('db_type' => 'enum("ready", "converting", "error", "finalizing")'));
     $updater = new FieldToEntityTable('media_work', $field_params);
     $updater->test_mode = $test_mode;
     $updater->update_entity_table();
     ob_start();
     $updater->report();
     $log .= ob_get_contents();
     ob_end_clean();
     return $log;
 }
 protected function _add_fields()
 {
     $updater = new FieldToEntityTable('policies', $this->_get_fields_to_add());
     $updater->update_entity_table();
     ob_start();
     $updater->report();
     return ob_get_clean();
 }
function create_external_url_type($type_id, $type_name, $type_unique_name, $type_plural_name, $entity_table_fields)
{
    $user_id = get_user_id(reason_require_authentication());
    if ($type_id == 0) {
        $type_id = reason_create_entity(id_of('master_admin'), id_of('type'), $user_id, $type_name, array('unique_name' => $type_unique_name, 'plural_name' => $type_plural_name, 'new' => 0));
        if ($type_id != 0) {
            report($type_name . ' type created');
            if (@create_default_rels_for_new_type($type_id, $type_unique_name)) {
                report($type_name . ' default rels created');
            }
        } else {
            warn($type_name . ' not created - this is unexpected');
            return false;
        }
    }
    if (!empty($entity_table_fields)) {
        foreach ($entity_table_fields as $table_name => $table_fields) {
            $table_id = @create_reason_table($table_name, $type_id, $user_id);
            if ($table_id) {
                report('created entity table ' . $table_name . ' with id ' . $table_id);
            } else {
                report('did not create entity table ' . $table_name . ' - probably already exists - will try to add to type');
                add_entity_table_to_type($table_name, $type_id);
            }
            $updater = new FieldToEntityTable($table_name, $table_fields);
            $updater->update_entity_table();
            if ($updater->fields > 0) {
                ob_start();
                $updater->report();
                $updater_report = '<h3>Amputee Report - entity table ' . $table_name . '</h3><hr />' . ob_get_contents() . '<hr />';
                ob_end_clean();
                report($updater_report);
            }
        }
        $fixer = new AmputeeFixer();
        $fixer->fix_amputees($type_id);
        report('fixed amputees for type ' . $type_name);
    } else {
        report($type_name . ' requires no entity table(s) because it has no fields other than what is in the entity table');
    }
    return $type_id;
}