protected function _execute()
 {
     log_open_block("Cleaning up indexes");
     $this->clean_up_folder_permissions('project_folder_permissions');
     $this->clean_up_user_permissions('project_user_permissions');
     $this->clean_up_id_indexes('project_entries');
     $this->clean_up_id_indexes('project_folders');
     $this->clean_up_id_indexes('project_comments');
     $this->clean_up_id_indexes('project_entries_to_branches');
     $this->_query('ALTER TABLE `project_changes` DROP INDEX `object_id`');
     $this->_query('ALTER TABLE `project_changes` ADD PRIMARY KEY ( `entry_id` )');
     $this->_query('ALTER TABLE `project_jobs` DROP INDEX `entry_id`');
     $this->_query('ALTER TABLE `project_jobs` ADD PRIMARY KEY ( `entry_id` )');
     $this->_query('ALTER TABLE `project_jobs_to_branches` DROP INDEX `entry_to_branch_id`');
     $this->_query('ALTER TABLE `project_jobs_to_branches` ADD PRIMARY KEY ( `entry_to_branch_id` )');
     $this->_query('ALTER TABLE `project_changes_to_branches` DROP INDEX `entry_to_branch_id`');
     $this->_query('ALTER TABLE `project_changes_to_branches` ADD PRIMARY KEY ( `entry_to_branch_id` )');
     $this->clean_up_subscriptions('project_subscriptions');
     $this->add_full_text_to_comments('project_comments');
     $this->add_folder_id_index('project_entries');
     log_close_block();
     log_open_block("Renaming subscriber fields");
     $this->rename_subscriber_fields('project_subscribers');
     $this->rename_action_table('project_actions', 'project_history_items');
     log_close_block();
 }
 protected function _execute()
 {
     log_open_block("Add features");
     $this->_query('ALTER TABLE `project_options` ADD `reporter_group_type` TINYINT DEFAULT \'0\' NOT NULL AFTER `assignee_group_id`');
     $this->_query('ALTER TABLE `project_options` ADD `reporter_group_id` INT UNSIGNED DEFAULT \'0\' NOT NULL AFTER `reporter_group_type`');
     log_close_block();
 }
 protected function _execute()
 {
     log_open_block("Updating fields");
     $this->_update_history_type_for_drafts('recipe_history_items');
     $this->_update_draft_state('recipes');
     log_close_block();
 }
 protected function _execute()
 {
     log_open_block("Adding settings to users");
     $this->_query("ALTER TABLE `users` ADD `email_visibility` ENUM( 'hidden', 'scrambled', 'visible' ) DEFAULT 'hidden' NOT NULL");
     $this->_query("UPDATE users SET email_visibility = 'scrambled'");
     log_close_block();
 }
 protected function _execute()
 {
     log_open_block("Cleaning text for comments...");
     $this->clean_text('news_comments');
     log_close_block();
     log_open_block("Cleaning text for folders...");
     $this->clean_text('news_folders');
     log_close_block();
     log_open_block("Cleaning text for entries...");
     $this->clean_text('news_articles');
     log_close_block();
     log_open_block("Updating subcribers table");
     $this->_query("ALTER TABLE `news_subscribers` CHANGE `send_as_newsletter` `group_objects` TINYINT( 4 ) DEFAULT '0' NOT NULL;");
     $this->_query("ALTER TABLE `news_subscribers` ADD `group_actions` TINYINT DEFAULT '0' NOT NULL AFTER `group_objects`;");
     log_close_block();
     log_open_block("Adding actions table");
     $this->_query("CREATE TABLE `news_actions` (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,`object_id` INT UNSIGNED NOT NULL ,`object_type` ENUM( 'folder', 'entry', 'comment', 'group', 'user' ) NOT NULL ,`user_id` INT UNSIGNED NOT NULL ,`access_id` INT UNSIGNED NOT NULL ,`kind` ENUM( 'Created', 'Updated', 'Deleted', 'Restored', 'Hidden', 'Hidden update' ) NOT NULL ,`time_created` DATETIME NOT NULL ,`publication_state` ENUM( 'silent', 'published', 'queued' ) NOT NULL ,`title` VARCHAR( 200 ) NOT NULL ,`description` TEXT NOT NULL ,`system_description` TEXT NOT NULL ,PRIMARY KEY ( `id` ) ,INDEX ( `object_id` , `object_type` ) );");
     log_close_block();
     log_open_block("Importing folder history...");
     $this->query("SELECT * from news_folders");
     $this->_create_actions('folder', 'news_actions');
     log_close_block();
     log_open_block("Importing article history...");
     $this->_query("SELECT * from news_articles");
     $this->_create_actions('entry', 'news_actions');
     log_close_block();
     log_open_block("Importing comment history...");
     $this->_query("SELECT com.*, entry.folder_id from news_comments com INNER JOIN project_entries entry ON entry.id = com.entry_id");
     $this->_create_actions('comment', 'news_actions');
     log_close_block();
 }
 protected function _execute()
 {
     log_open_block("Updating summary in folders");
     $this->_query('ALTER TABLE `recipe_folders` DROP INDEX `id_2`');
     $this->_query('ALTER TABLE `recipe_subscriptions` DROP INDEX `email`');
     $this->_update_folders('recipe_folders');
     log_close_block();
 }
 public function add_attachment_permissions($folder_table_name, $user_table_name)
 {
     log_open_block("Add attachment permissions...");
     $this->_query("ALTER TABLE `{$user_table_name}` ADD `deny_attachment_permissions` SMALLINT UNSIGNED NOT NULL AFTER `deny_entry_permissions` ;");
     $this->_query("ALTER TABLE `{$user_table_name}` ADD `allow_attachment_permissions` SMALLINT UNSIGNED NOT NULL AFTER `allow_entry_permissions` ;");
     $this->_query("ALTER TABLE `{$folder_table_name}` ADD `attachment_permissions` SMALLINT UNSIGNED NOT NULL AFTER `entry_permissions` ;");
     log_close_block();
 }
 protected function _execute()
 {
     if ($this->db->table_exists('themes')) {
         log_open_block("Updating default themes");
         $this->_query("UPDATE `themes` SET main_CSS_file_name=REPLACE(main_CSS_file_name, '{styles}themes', '{themes}');");
         log_close_block();
     }
 }
 protected function _execute()
 {
     log_open_block("Updating users table");
     $this->_query("ALTER TABLE `users` ADD `kind` ENUM( 'anonymous', 'registered' ) DEFAULT 'anonymous' NOT NULL");
     $this->_query("UPDATE `users` SET kind = 'registered' WHERE type = 4;");
     $this->_query("ALTER TABLE `users` DROP `type`, DROP `icon_id`");
     $this->_query('DROP TABLE `user_icons`');
     log_close_block();
 }
 /**
  * Perform setup for a process that will run.
  * {@link _can_be_executed()} has returned True.
  * @access private
  */
 protected function _pre_execute()
 {
     if (!$this->db->table_exists('versions')) {
         log_open_block("Adding version table");
         $this->_query("CREATE TABLE `versions` (`title` varchar(100) NOT NULL default '', `version` varchar(50) NOT NULL default '')");
         $this->_query("ALTER TABLE `versions` ADD PRIMARY KEY ( `title` ); ");
         log_close_block();
     }
 }
 protected function _execute()
 {
     log_open_block("Updating summary in folders");
     $this->_query('ALTER TABLE `project_folders` DROP INDEX `id_2`');
     $this->_query('ALTER TABLE `project_branches` DROP INDEX `id`');
     $this->_query('ALTER TABLE `project_releases` DROP INDEX `id`');
     $this->_update_folders('project_folders');
     log_close_block();
 }
 function _execute()
 {
     log_open_block("Updating names [object => entry]...");
     $this->_query("ALTER TABLE `recipe_subscriptions` CHANGE `watch_objects` `watch_entries` TINYINT( 4 ) UNSIGNED DEFAULT '0' NOT NULL");
     $this->_query("ALTER TABLE `recipe_comments` CHANGE `object_id` `entry_id` INT( 11 ) UNSIGNED DEFAULT '0' NOT NULL");
     log_close_block();
     log_open_block("Building recipe tree...");
     $this->_query("CREATE TABLE `recipe_tree` (`parent_id` INT UNSIGNED NOT NULL ,`child_id` INT UNSIGNED NOT NULL)");
     $this->_query("SELECT * from recipe_folders");
     $this->build_folder_tree('recipe_tree');
     log_close_block();
 }
 protected function _execute()
 {
     log_open_block("Adding owners to objects");
     $this->add_owner_to_table('album_attachments');
     $this->add_owner_to_table('album_comments');
     $this->add_owner_to_table('album_entries');
     $this->add_owner_to_table('album_folders');
     log_close_block();
     $this->add_organizational('album_folders');
     log_open_block("Adding version information");
     $this->add_version_info('albums_application', 'earthli Albums', '2.8.0');
     log_close_block();
 }
 protected function _execute()
 {
     log_open_block("Adding actions table");
     $this->_query("CREATE TABLE `project_actions` (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,`object_id` INT UNSIGNED NOT NULL ,`object_type` ENUM( 'folder', 'entry', 'comment', 'group', 'user', 'branch', 'release' ) NOT NULL ,`user_id` INT UNSIGNED NOT NULL ,`time_created` DATETIME NOT NULL ,`publication_state` ENUM( 'silent', 'published', 'queued' ) NOT NULL ,`title` VARCHAR( 200 ) NOT NULL ,`description` TEXT NOT NULL ,`system_description` TEXT NOT NULL ,PRIMARY KEY ( `id` ) ,INDEX ( `object_id` , `object_type` ) );");
     log_close_block();
     log_open_block("Importing group history...");
     $this->_query("SELECT * from groups");
     $this->_create_actions('group');
     log_close_block();
     log_open_block("Importing user history...");
     $this->_query("SELECT * from users");
     $this->_create_actions('user');
     log_close_block();
 }
 protected function _execute()
 {
     $this->add_attachments('album_attachments', 'album_actions');
     $this->update_actions('album_actions');
     $this->update_subscriptions('album_subscribers', 'album_subscriptions');
     $this->update_permissions('album_folder_permissions', 'album_user_permissions');
     $this->update_drafting('album_entries');
     $this->update_folders('album_folders');
     $this->update_users('album_user_permissions');
     log_open_block("Updating album properties");
     $this->_query("ALTER TABLE `album_folders` CHANGE `opt_show_times` `show_times` TINYINT( 4 ) DEFAULT '0' NOT NULL ,\n                      CHANGE `opt_show_celsius` `show_celsius` TINYINT( 4 ) DEFAULT '1' NOT NULL ,\n                      CHANGE `opt_first_day_mode` `first_day_mode` TINYINT( 4 ) DEFAULT '0' NOT NULL ,\n                      CHANGE `opt_last_day_mode` `last_day_mode` TINYINT( 4 ) DEFAULT '0' NOT NULL ,\n                      CHANGE `opt_max_picture_width` `max_picture_width` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL ,\n                      CHANGE `opt_max_picture_height` `max_picture_height` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL");
     $this->_query("ALTER TABLE `album_folders` ADD `location` ENUM( 'local', 'remote' ) NOT NULL AFTER `max_picture_height` ;");
     log_close_block();
 }
 protected function _execute()
 {
     log_open_block("Updating names [object => entry]...");
     $this->_query("ALTER TABLE `album_objects` RENAME `album_entries`");
     $this->_query("ALTER TABLE `album_subscriptions` CHANGE `watch_objects` `watch_entries` TINYINT( 4 ) UNSIGNED DEFAULT '0' NOT NULL");
     $this->_query("ALTER TABLE `album_journal` CHANGE `object_id` `entry_id` INT( 11 ) UNSIGNED DEFAULT '0' NOT NULL");
     $this->_query("ALTER TABLE `album_pictures` CHANGE `object_id` `entry_id` INT( 11 ) UNSIGNED DEFAULT '0' NOT NULL");
     $this->_query("ALTER TABLE `album_comments` CHANGE `object_id` `entry_id` INT( 11 ) UNSIGNED DEFAULT '0' NOT NULL");
     log_close_block();
     log_open_block("Building album tree...");
     $this->_query("CREATE TABLE `album_tree` (`parent_id` INT UNSIGNED NOT NULL ,`child_id` INT UNSIGNED NOT NULL)");
     $this->_query("SELECT * from album_folders");
     $this->build_folder_roots('album_tree');
     log_close_block();
 }
 protected function _execute()
 {
     $this->add_attachments('news_attachments', 'news_actions');
     $this->update_actions('news_actions', 'news_comments', 'news_folders', 'news_articles');
     $this->update_subscriptions('news_subscribers', 'news_subscriptions');
     $this->update_permissions('news_folder_permissions', 'news_user_permissions');
     $this->update_drafting('news_articles');
     $this->update_folders('news_folders');
     $this->update_users('news_user_permissions');
     log_open_block('Replacing obsolete tags');
     $this->_query("UPDATE news_articles SET description=REPLACE(description, '<h3>', '<h>') WHERE LOCATE('<h3>', description) > 0;");
     $this->_query("UPDATE news_articles SET description=REPLACE(description, '</h3>', '</h>') WHERE LOCATE('</h3>', description) > 0;");
     $this->_query("UPDATE news_articles SET description=REPLACE(description, '</h4>', '</h>') WHERE LOCATE('</h4>', description) > 0;");
     $this->_query("UPDATE news_articles SET description=REPLACE(description, '<h4>', '<h level=\"4\">') WHERE LOCATE('<h4>', description) > 0;");
     log_close_block();
 }
 protected function _execute()
 {
     $this->add_attachments('recipe_attachments', 'recipe_actions');
     $this->add_attachment_permissions('recipe_folder_permissions', 'recipe_user_permissions');
     log_open_block("Adding owners to objects");
     $this->add_owner_to_table('recipe_attachments');
     $this->add_owner_to_table('recipe_comments');
     $this->add_owner_to_table('recipes');
     $this->add_owner_to_table('recipe_folders');
     log_close_block();
     $this->add_version_info('recipe_application', 'earthli Recipes', '1.6.0');
     $this->add_organizational('recipe_folders');
     log_open_block("Updating originator size.");
     $this->_query('ALTER TABLE `recipes` CHANGE `originator` `originator` VARCHAR( 255 ) NOT NULL');
     log_close_block();
 }
 protected function _execute()
 {
     log_open_block("Cleaning up indexes");
     $this->clean_up_folder_permissions('news_folder_permissions');
     $this->clean_up_user_permissions('news_user_permissions');
     $this->clean_up_id_indexes('news_articles');
     $this->clean_up_id_indexes('news_folders');
     $this->clean_up_id_indexes('news_comments');
     $this->clean_up_subscriptions('news_subscriptions');
     $this->add_full_text_to_comments('news_comments');
     $this->add_folder_id_index('news_articles');
     log_close_block();
     log_open_block("Renaming subscriber fields");
     $this->rename_subscriber_fields('news_subscribers');
     $this->rename_action_table('news_actions', 'news_history_items');
     log_close_block();
 }
 protected function _execute()
 {
     log_open_block("Adding owners to objects");
     $this->add_owner_to_table('news_attachments');
     $this->add_owner_to_table('news_comments');
     $this->add_owner_to_table('news_articles');
     $this->add_owner_to_table('news_folders');
     log_close_block();
     $this->add_organizational('news_folders');
     $this->add_version_info('news_application', 'earthli News', '2.7.0');
     log_open_block('Replacing obsolete tags');
     $this->_query("UPDATE news_articles SET description=REPLACE(description, '{attachment}', '{att_link}') WHERE LOCATE('{attachment}', description) > 0;");
     $this->_query("UPDATE news_articles SET description=REPLACE(description, '{thumbnail}', '{att_thumb}') WHERE LOCATE('{thumbnail}', description) > 0;");
     $this->_query("UPDATE news_articles SET description=REPLACE(description, '<code>', '<c>') WHERE LOCATE('<code>', description) > 0;");
     $this->_query("UPDATE news_articles SET description=REPLACE(description, '</code>', '</c>') WHERE LOCATE('</code>', description) > 0;");
     log_close_block();
 }
 protected function _execute()
 {
     log_open_block("Updating theme table fields...");
     $this->_query("ALTER TABLE `themes` CHANGE `name` `title` VARCHAR( 100 ) NOT NULL , CHANGE `file` `main_CSS_file_name` VARCHAR( 100 ) NOT NULL , CHANGE `color` `icon_set` VARCHAR( 100 ) NOT NULL , CHANGE `renderer` `renderer_class_name` VARCHAR( 100 ) NOT NULL");
     $this->_query("ALTER TABLE `themes` ADD `font_name_CSS_file_name` VARCHAR( 100 ) NOT NULL AFTER `main_CSS_file_name` ,ADD `font_size_CSS_file_name` VARCHAR( 100 ) NOT NULL AFTER `font_name_CSS_file_name`");
     $this->_query("ALTER TABLE `themes` ADD `icon_extension` VARCHAR( 5 ) NOT NULL AFTER `icon_set`");
     $this->_query("UPDATE themes SET icon_set = ''");
     $this->_query("UPDATE themes SET renderer_class_name = 'DEFAULT_PAGE_RENDERER' WHERE renderer_class_name = 'EARTHLI_RENDERER'");
     $this->_query("UPDATE themes SET renderer_class_name = 'OPUS_PAGE_RENDERER' WHERE renderer_class_name = 'OPUS_RENDERER'");
     $this->_query("ALTER TABLE `themes` CHANGE `renderer_class_name` `renderer_class_name` VARCHAR( 100 ) NOT NULL ");
     $this->_query("ALTER TABLE `themes` DROP `group_name`");
     $this->_query("ALTER TABLE `themes` CHANGE `name` `title` VARCHAR( 100 ) NOT NULL , CHANGE `file` `main_CSS_file_name` VARCHAR( 100 ) NOT NULL , CHANGE `color` `icon_set` VARCHAR( 100 ) NOT NULL , CHANGE `renderer` `renderer_class_name` VARCHAR( 100 ) NOT NULL");
     $this->_query("ALTER TABLE `themes` ADD `font_name_CSS_file_name` VARCHAR( 100 ) NOT NULL AFTER `main_CSS_file_name` ,ADD `font_size_CSS_file_name` VARCHAR( 100 ) NOT NULL AFTER `font_name_CSS_file_name`");
     $this->_query("ALTER TABLE `themes` ADD `icon_extension` VARCHAR( 5 ) NOT NULL AFTER `icon_set`");
     $this->_query("UPDATE themes SET icon_set = ''");
     $this->_query("ALTER TABLE `themes` CHANGE `renderer_class_name` `renderer_class_name` VARCHAR( 100 ) NOT NULL ");
     log_close_block();
 }
 protected function _execute()
 {
     log_open_block("Adding test time to release");
     $this->_query('ALTER TABLE `project_releases` ADD `time_testing_scheduled` DATETIME AFTER `time_scheduled` ;');
     $this->_query('ALTER TABLE `project_releases` ADD `time_tested` DATETIME AFTER `time_scheduled` ;');
     $this->_query('ALTER TABLE `project_releases` ADD `time_next_deadline` DATETIME AFTER `time_scheduled` ;');
     $this->_query('ALTER TABLE `project_releases` ADD `summary` TEXT');
     $this->_query('ALTER TABLE `project_releases` ADD FULLTEXT (`summary`)');
     log_close_block();
     log_open_block("Changing owner to assignee");
     $this->_query('ALTER TABLE `project_options` CHANGE `owner_group_type` `assignee_group_type` TINYINT( 4 ) DEFAULT \'0\' NOT NULL');
     $this->_query('ALTER TABLE `project_options` CHANGE `owner_group_id` `assignee_group_id` INT( 10 ) UNSIGNED DEFAULT \'0\' NOT NULL');
     $this->_query('ALTER TABLE `project_jobs` CHANGE `owner_id` `assignee_id` INT( 10 ) UNSIGNED DEFAULT \'0\' NOT NULL');
     $this->_query('ALTER TABLE `project_jobs` CHANGE `time_owner_changed` `time_assignee_changed` DATETIME DEFAULT \'0000-00-00 00:00:00\' NOT NULL');
     log_close_block();
     $this->add_attachments('project_attachments', 'project_actions');
     $this->_query("ALTER TABLE `project_actions` CHANGE `object_type` `object_type` ENUM( 'folder', 'entry', 'comment', 'group', 'user', 'branch', 'release', 'component', 'attachment' ) DEFAULT 'folder' NOT NULL");
     $this->_query("ALTER TABLE `project_branches` DROP `publication_state`");
     $this->_query("ALTER TABLE `project_releases` DROP `publication_state`");
     $this->add_attachment_permissions('project_folder_permissions', 'project_user_permissions');
     log_open_block("Adding owners to objects");
     $this->add_owner_to_table('project_attachments');
     $this->add_owner_to_table('project_comments');
     $this->add_owner_to_table('project_entries');
     $this->add_owner_to_table('project_folders');
     $this->add_owner_to_table('project_releases');
     $this->add_owner_to_table('project_branches');
     $this->add_owner_to_table('project_components');
     log_close_block();
     $this->add_version_info('project_application', 'earthli Projects', '1.8.0');
     $this->add_organizational('project_folders');
     log_open_block('Replacing obsolete tags');
     $this->_query("UPDATE project_entries SET description=REPLACE(description, '<code>', '<c>') WHERE LOCATE('<code>', description) > 0;");
     $this->_query("UPDATE project_entries SET description=REPLACE(description, '</code>', '</c>') WHERE LOCATE('</code>', description) > 0;");
     log_close_block();
     log_open_block('Adding project options');
     $this->_query("ALTER TABLE `project_options` ADD `seconds_until_deadline` INT UNSIGNED NOT NULL ;");
     log_close_block();
     log_open_block('Adding fulltext indexes');
     $this->_query('ALTER TABLE `project_entries` ADD FULLTEXT (`extra_description`)');
     log_close_block();
 }
 protected function _execute()
 {
     log_open_block("Cleaning up indexes");
     $this->clean_up_folder_permissions('album_folder_permissions');
     $this->clean_up_user_permissions('album_user_permissions');
     $this->clean_up_id_indexes('album_entries');
     $this->clean_up_id_indexes('album_folders');
     $this->clean_up_id_indexes('album_comments');
     $this->_query('ALTER TABLE `album_journal` DROP INDEX `entry_id`');
     $this->_query('ALTER TABLE `album_journal` ADD PRIMARY KEY ( `entry_id` )');
     $this->_query('ALTER TABLE `album_pictures` DROP INDEX `entry_id`');
     $this->_query('ALTER TABLE `album_pictures` ADD PRIMARY KEY ( `entry_id` )');
     $this->clean_up_subscriptions('album_subscriptions');
     $this->add_full_text_to_comments('album_comments');
     log_close_block();
     log_open_block("Renaming subscriber fields");
     $this->rename_subscriber_fields('album_subscribers');
     $this->rename_action_table('album_actions', 'album_history_items');
     log_close_block();
 }
 protected function _execute()
 {
     if (!$this->db->table_exists('versions')) {
         log_open_block("Adding version table");
         $this->_query("CREATE TABLE `versions` (`title` varchar(100) NOT NULL default '', `version` varchar(50) NOT NULL default '')");
         $this->_query("ALTER TABLE `versions` ADD PRIMARY KEY ( `title` ); ");
         log_close_block();
     }
     log_open_block("Removing unneeded indexes");
     $this->_query("ALTER TABLE `users` DROP INDEX `id`");
     log_close_block();
     log_open_block("Added fulltext indexes");
     $this->_query("ALTER TABLE `users` ADD FULLTEXT (`title`)");
     $this->_query("ALTER TABLE `users` ADD FULLTEXT (`description`)");
     $this->_query("ALTER TABLE `users` ADD FULLTEXT (`real_first_name`)");
     $this->_query("ALTER TABLE `users` ADD FULLTEXT (`real_last_name`)");
     $this->_query("ALTER TABLE `users` ADD FULLTEXT (`home_page_url`)");
     $this->_query("ALTER TABLE `users` ADD FULLTEXT (`email`)");
     $this->_query("ALTER TABLE `users` ADD FULLTEXT (`picture_url`)");
     $this->_query("ALTER TABLE `users` ADD FULLTEXT (`signature`)");
     log_close_block();
 }
 protected function _execute()
 {
     $this->update_actions('project_actions', 'project_comments', 'project_folders', 'project_entries');
     $this->update_subscriptions('project_subscribers', 'project_subscriptions');
     $this->update_permissions('project_folder_permissions', 'project_user_permissions');
     $this->update_folders('project_folders');
     $this->update_users('project_user_permissions');
     log_open_block("Adding extended times to jobs");
     $this->_query('ALTER TABLE `project_jobs` ADD `time_status_changed` DATETIME NOT NULL ;');
     $this->_query('ALTER TABLE `project_jobs_to_branches` ADD `branch_time_status_changed` DATETIME NOT NULL ;');
     $this->_query('ALTER TABLE `project_jobs` ADD `time_owner_changed` DATETIME NOT NULL ;');
     log_close_block();
     log_open_block("Adding new status to releases");
     $this->_query('ALTER TABLE `project_releases` ADD `time_shipped` DATETIME NOT NULL AFTER `time_scheduled` ;');
     $this->_query('UPDATE `project_releases` SET time_shipped = time_scheduled WHERE (state = ' . Locked . ') OR (state = ' . Shipped . ')');
     log_close_block();
     log_open_block("Adding components");
     $this->_query("ALTER TABLE `project_actions` CHANGE `object_type` `object_type` ENUM( 'folder', 'entry', 'comment', 'group', 'user', 'branch', 'release', 'component' ) DEFAULT 'folder' NOT NULL");
     $this->_query("CREATE TABLE `project_components` (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,`folder_id` INT UNSIGNED NOT NULL ,`title` VARCHAR( 100 ) NOT NULL ,`description` TEXT NOT NULL ,`icon_url` VARCHAR( 250 ) NOT NULL ,INDEX ( `id` ) );");
     $this->_query("ALTER TABLE `project_components` ADD `creator_id` INT UNSIGNED NOT NULL ,ADD `modifier_id` INT UNSIGNED NOT NULL ,ADD `time_created` DATETIME NOT NULL ,ADD `time_modified` DATETIME NOT NULL ;");
     $this->_query("ALTER TABLE `project_components` ADD `state` TINYINT UNSIGNED NOT NULL AFTER `icon_url` ;");
     $this->_query("ALTER TABLE `project_entries` ADD `component_id` INT UNSIGNED NOT NULL AFTER `folder_id` ;");
     log_close_block();
 }
 protected function _execute()
 {
     log_open_block("Adding [time_needed] to JOB...");
     $this->_query("ALTER TABLE `project_jobs` ADD `time_needed` DATETIME NOT NULL");
     $this->_query("ALTER TABLE `project_objects` ADD `extra_description` TEXT NOT NULL");
     log_close_block();
     log_open_block("Updating names [revision => release]...");
     $this->_query("ALTER TABLE `project_revisions` RENAME `project_releases`");
     log_close_block();
     log_open_block("Updating names [object => entry]...");
     $this->_query("ALTER TABLE `project_objects` RENAME `project_entries`");
     $this->_query("ALTER TABLE `project_subscriptions` CHANGE `watch_objects` `watch_entries` TINYINT( 4 ) UNSIGNED DEFAULT '0' NOT NULL");
     $this->_query("ALTER TABLE `project_jobs` CHANGE `object_id` `entry_id` INT( 11 ) UNSIGNED DEFAULT '0' NOT NULL");
     $this->_query("ALTER TABLE `project_changes` CHANGE `object_id` `entry_id` INT( 11 ) UNSIGNED DEFAULT '0' NOT NULL");
     $this->_query("ALTER TABLE `project_comments` CHANGE `object_id` `entry_id` INT( 11 ) UNSIGNED DEFAULT '0' NOT NULL");
     log_close_block();
     log_open_block("Adding branching data structures...");
     $this->_query("ALTER TABLE `project_entries` ADD `main_branch_id` INT( 11 ) UNSIGNED DEFAULT '0' NOT NULL");
     $this->_query("CREATE TABLE project_branches (id int(10) unsigned NOT NULL auto_increment, folder_id int(10) unsigned NOT NULL default '0', parent_release_id int(10) unsigned NOT NULL default '0', state tinyint(3) unsigned NOT NULL default '1', title varchar(100) NOT NULL default '', description text NOT NULL, time_created datetime default NULL, time_modified datetime default NULL, creator_id int(10) unsigned NOT NULL default '0', modifier_id int(10) unsigned NOT NULL default '0', publication_state tinyint(3) unsigned NOT NULL default '0', PRIMARY KEY  (id), KEY id (id))");
     $this->_query("CREATE TABLE `project_entries_to_branches` (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `entry_id` INT UNSIGNED NOT NULL, `branch_id` INT UNSIGNED NOT NULL, `branch_release_id` INT UNSIGNED NOT NULL, PRIMARY KEY  (id), KEY id (id) )");
     $this->_query("CREATE TABLE `project_jobs_to_branches` (`entry_to_branch_id` INT UNSIGNED NOT NULL, `branch_status` TINYINT UNSIGNED,`branch_priority` TINYINT UNSIGNED,`branch_closer_id` INT UNSIGNED,`branch_time_closed` DATETIME)");
     $this->_query("CREATE TABLE `project_changes_to_branches` (`entry_to_branch_id` INT UNSIGNED NOT NULL, `branch_applier_id` INT UNSIGNED,`branch_time_applied` DATETIME)");
     $this->_query("ALTER TABLE `project_folders` ADD `trunk_id` INT( 11 ) UNSIGNED DEFAULT '0' NOT NULL");
     $this->_query("ALTER TABLE `project_releases` CHANGE `folder_id` `branch_id` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL");
     $this->_query("ALTER TABLE `project_releases` ADD `time_scheduled` DATETIME NOT NULL AFTER `description`");
     $this->_query("ALTER TABLE `project_changes` ADD `applier_id` INT UNSIGNED, ADD `time_applied` DATETIME");
     log_close_block();
     log_open_block("Creating [Dev] branch for each project...");
     $this->_query("SELECT * from project_folders");
     $folder_ids = array();
     while ($Page->database->next_record()) {
         $folder_ids[] = $Page->database->f('id');
     }
     $branch_map = array();
     foreach ($folder_ids as $id) {
         $this->_query("INSERT INTO project_branches (folder_id, title, time_created, time_modified, creator_id, modifier_id) VALUES({$id}, 'Dev Branch', NOW(), NOW(), {$default_user_id}, {$default_user_id})");
         $this->_query("SELECT MAX(id) from project_branches");
         $Page->database->next_record();
         $branch_id = $Page->database->f(0);
         $this->_query("UPDATE project_folders SET trunk_id = {$branch_id} WHERE id = {$id}");
         $branch_map[$id] = $branch_id;
     }
     $this->_query("SELECT * from project_releases");
     $release_ids = array();
     while ($Page->database->next_record()) {
         $release_ids[$Page->database->f('id')] = $Page->database->f('branch_id');
     }
     log_close_block();
     log_open_block("Mapping releases to [Dev] branches...");
     foreach ($release_ids as $id => $folder_id) {
         $branch_id = $branch_map[$folder_id];
         if (!$branch_id) {
             $this->_log("Did not find mapping for id = [{$id}], folder id = [{$folder_id}]", Msg_type_warning);
         } else {
             $this->_query("UPDATE project_releases SET time_scheduled = time_created, branch_id = {$branch_id}, state = 5 WHERE id = {$id}");
         }
     }
     log_close_block();
     log_open_block("Mapping changes to [Dev] branches...");
     $this->_query("SELECT * from project_entries WHERE type = 'change'");
     $change_ids = array();
     while ($Page->database->next_record()) {
         $change_ids[$Page->database->f('id')] = array($Page->database->f('folder_id'), $Page->database->f('revision_id'), $Page->database->f('time_created'), $Page->database->f('creator_id'));
     }
     foreach ($change_ids as $id => $other_ids) {
         $folder_id = $other_ids[0];
         $branch_id = $branch_map[$folder_id];
         $revision_id = $other_ids[1];
         $time_applied = $other_ids[2];
         $applier_id = $other_ids[3];
         if (!$branch_id) {
             log_message("No project found for id [{$folder_id}] (change [{$id}] not imported).", Msg_type_warning, Msg_channel_migrate);
         } else {
             $this->_query("INSERT INTO project_entries_to_branches (entry_id, branch_id, branch_release_id) VALUES ({$id}, {$branch_id}, {$revision_id})");
             $this->_query("SELECT MAX(id) from project_entries_to_branches");
             $Page->database->next_record();
             $entry_to_branch_id = $Page->database->f(0);
             $this->_query("INSERT INTO project_changes_to_branches (entry_to_branch_id, branch_time_applied, branch_applier_id) VALUES ({$entry_to_branch_id}, '{$time_applied}', {$applier_id})");
             $this->_query("UPDATE project_entries SET main_branch_id = {$branch_id} WHERE id = {$id}");
             $this->_query("UPDATE project_changes SET applier_id = {$applier_id}, time_applied = '{$time_applied}' WHERE entry_id = {$id}");
         }
     }
     log_close_block();
     log_open_block("Converting job statuses (building job status map)...");
     // convert re-opened status
     $this->_query("UPDATE project_jobs SET status = 1 WHERE status = 50");
     // convert closed status
     $this->_query("UPDATE project_jobs SET status = 9 WHERE status = 100");
     // convert abandoned status
     $this->_query("UPDATE project_jobs SET status = 10 WHERE status = 150");
     // convert working status
     $this->_query("UPDATE project_jobs SET status = 3 WHERE status = 70");
     // convert fixed status
     $this->_query("UPDATE project_jobs SET status = 7 WHERE status = 90");
     log_close_block();
     log_open_block("Converting job priorities (building job priority map)...");
     // convert "Not needed for release"
     $this->_query("UPDATE project_jobs SET priority = 0 WHERE priority = 10");
     // convert "Needed for release"
     $this->_query("UPDATE project_jobs SET priority = 1 WHERE priority = 20");
     // convert "Needed for release: workaround exists"
     $this->_query("UPDATE project_jobs SET priority = 2 WHERE priority = 30");
     // convert "Needed for release: no workaround found"
     $this->_query("UPDATE project_jobs SET priority = 3 WHERE priority = 40");
     // convert "Showstopper: cannot continue working"
     $this->_query("UPDATE project_jobs SET priority = 4 WHERE priority = 50");
     log_close_block();
     log_open_block("Mapping jobs to [Dev] branches...");
     $this->_query("SELECT * from project_entries INNER JOIN project_jobs ON project_entries.id = project_jobs.entry_id");
     $job_ids = array();
     while ($Page->database->next_record()) {
         $job_ids[$Page->database->f('id')] = array($Page->database->f('folder_id'), $Page->database->f('revision_id'), $Page->database->f('status'), $Page->database->f('priority'), $Page->database->f('closer_id'), $Page->database->f('owner_id'), $Page->database->f('time_closed'));
     }
     foreach ($job_ids as $id => $other_ids) {
         $folder_id = $other_ids[0];
         $branch_id = $branch_map[$folder_id];
         $revision_id = $other_ids[1];
         $status = $other_ids[2];
         $priority = $other_ids[3];
         $closer_id = $other_ids[4];
         $owner_id = $other_ids[5];
         $time_closed = $other_ids[6];
         if (!$branch_id) {
             log_message("No project found for id [{$folder_id}] (job [{$id}] not imported).", Msg_type_warning, Msg_channel_migrate);
         } else {
             $this->_query("INSERT INTO project_entries_to_branches (entry_id, branch_id, branch_release_id) VALUES ({$id}, {$branch_id}, {$revision_id})");
             $this->_query("SELECT MAX(id) from project_entries_to_branches");
             $Page->database->next_record();
             $entry_to_branch_id = $Page->database->f(0);
             $this->_query("INSERT INTO project_jobs_to_branches (entry_to_branch_id, branch_status, branch_priority, branch_closer_id, branch_time_closed) VALUES ({$entry_to_branch_id}, {$status}, {$priority}, {$closer_id}, '{$time_closed}')");
             $this->_query("UPDATE project_entries SET main_branch_id = {$branch_id} WHERE id = {$id}");
         }
     }
     log_close_block();
     log_open_block("Renaming [revision_id] to [release_id] in entries...");
     $this->_query("ALTER TABLE `project_entries` CHANGE `revision_id` `release_id` INT( 11 ) UNSIGNED DEFAULT '0' NOT NULL");
     log_close_block();
     log_open_block("Removing [priority, status, closer_id, time_closed] from jobs...");
     $this->_query("ALTER TABLE `project_jobs` DROP `priority`, DROP `status`, DROP `closer_id`, DROP `time_closed`");
     log_close_block();
     log_open_block("Building project tree...");
     $this->_query("CREATE TABLE `project_tree` (`parent_id` INT UNSIGNED NOT NULL ,`child_id` INT UNSIGNED NOT NULL)");
     $this->_query("SELECT * from project_folders");
     $this->build_folder_roots('project_tree');
     log_close_block();
 }
    public function add_attachments($table_name, $action_table_name)
    {
        log_open_block("Adding attachments...");
        $s = <<<EOD
CREATE TABLE {$table_name} (
              `id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
              `object_id` INT UNSIGNED NOT NULL ,
              `state` TINYINT UNSIGNED NOT NULL ,
              `type` ENUM( 'folder', 'entry', 'comment', 'user', 'group' ) NOT NULL ,
              `title` VARCHAR( 200 ) NOT NULL ,
              `description` TEXT NOT NULL ,
              `file_name` VARCHAR( 200 ) NOT NULL ,
              `original_file_name` VARCHAR( 200 ) NOT NULL ,
              `size` INT NOT NULL ,
              `mime_type` VARCHAR( 100 ) NOT NULL ,
              `is_image` TINYINT UNSIGNED NOT NULL ,
              `is_archive` TINYINT UNSIGNED NOT NULL ,
              `time_created` datetime default '0000-00-00 00:00:00',
              `time_modified` datetime default '0000-00-00 00:00:00',
              `creator_id` int(10) unsigned NOT NULL default '0',
              `modifier_id` int(10) unsigned NOT NULL default '0',
              PRIMARY KEY ( `id` )
              );
EOD;
        $this->_query($s);
        $this->_query("ALTER TABLE {$action_table_name} CHANGE `object_type` `object_type` ENUM( 'folder', 'entry', 'comment', 'group', 'user', 'attachment' ) DEFAULT 'folder' NOT NULL");
        log_close_block();
    }
 protected function _execute()
 {
     log_open_block("Repairing change to branch map...");
     $this->_query("SELECT entry.id as entry_id, time_created, creator_id, etob.id as entry_to_branch_id from project_entries entry INNER JOIN project_entries_to_branches etob ON entry.id = etob.entry_id LEFT JOIN project_changes_to_branches ctob on etob.id = ctob.entry_to_branch_id WHERE ISNULL(ctob.entry_to_branch_id)");
     $changes = array();
     while ($Page->database->next_record()) {
         $changes[$Page->database->f('entry_to_branch_id')] = array($Page->database->f('time_created'), $Page->database->f('creator_id'), $Page->database->f('entry_id'));
     }
     if (sizeof($changes)) {
         log_message("Repairing [" . sizeof($changes) . "] changes...", Msg_type_warning, Msg_channel_migrate);
         foreach ($changes as $etob_id => $change) {
             $time_applied = $change[0];
             $applier_id = $change[1];
             $change_id = $change[2];
             $this->_query("INSERT INTO project_changes_to_branches (entry_to_branch_id, branch_time_applied, branch_applier_id) VALUES ({$etob_id}, '{$time_applied}', {$applier_id})");
             $this->_query("UPDATE project_changes SET applier_id = {$applier_id}, time_applied = '{$time_applied}' WHERE entry_id = {$change_id}");
         }
     }
     log_close_block();
     log_open_block("Cleaning text for comments...");
     $this->clean_text('project_comments');
     log_close_block();
     log_open_block("Cleaning text for folders...");
     $this->clean_text('project_folders');
     log_close_block();
     log_open_block("Cleaning text for entries...");
     $this->clean_text('project_entries');
     log_close_block();
     log_open_block("Cleaning text for releases...");
     $this->clean_text('project_releases');
     log_close_block();
     log_open_block("Cleaning text for branches...");
     $this->clean_text('project_branches');
     log_close_block();
     log_open_block("Updating subcribers table");
     $this->_query("ALTER TABLE `project_subscribers` CHANGE `send_as_newsletter` `group_objects` TINYINT( 4 ) DEFAULT '0' NOT NULL;");
     $this->_query("ALTER TABLE `project_subscribers` ADD `group_actions` TINYINT DEFAULT '0' NOT NULL AFTER `group_objects`;");
     log_close_block();
     log_open_block("Adding actions table");
     $this->_query("CREATE TABLE `project_actions` (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,`object_id` INT UNSIGNED NOT NULL ,`object_type` ENUM( 'folder', 'entry', 'comment', 'group', 'user', 'branch', 'release' ) NOT NULL ,`access_id` INT UNSIGNED NOT NULL ,`kind` ENUM( 'Created', 'Updated', 'Deleted', 'Restored', 'Hidden', 'Hidden update' ) NOT NULL ,`user_id` INT UNSIGNED NOT NULL ,`time_created` DATETIME NOT NULL ,`publication_state` ENUM( 'silent', 'published', 'queued' ) NOT NULL ,`title` VARCHAR( 200 ) NOT NULL ,`description` TEXT NOT NULL ,`system_description` TEXT NOT NULL ,PRIMARY KEY ( `id` ) ,INDEX ( `object_id` , `object_type` ) );");
     log_close_block();
     log_open_block("Importing folder history...");
     $this->_query("SELECT * from project_folders");
     $this->_create_actions('folder', 'project_actions');
     log_close_block();
     log_open_block("Importing change history...");
     $this->_query("SELECT * from project_entries WHERE type = 'change'");
     $this->_create_actions('entry', 'project_actions');
     log_close_block();
     log_open_block("Importing job history...");
     $this->_query("SELECT * from project_entries WHERE type = 'job'");
     $this->_create_actions('entry', 'project_actions');
     log_close_block();
     log_open_block("Importing release history...");
     $this->_query("SELECT rel.*, bra.folder_id from project_releases rel INNER JOIN project_branches bra ON rel.branch_id = bra.id");
     $this->_create_actions('release', 'project_actions');
     log_close_block();
     log_open_block("Importing branch history...");
     $this->_query("SELECT * from project_branches");
     $this->_create_actions('branch', 'project_actions');
     log_close_block();
     log_open_block("Importing comment history...");
     $this->_query("SELECT com.*, entry.folder_id from project_comments com INNER JOIN project_entries entry ON entry.id = com.entry_id");
     $this->_create_actions('comment', 'project_actions');
     log_close_block();
     log_open_block("Importing group history...");
     $this->_query("SELECT * from groups");
     $this->_create_actions('group', 'project_actions');
     log_close_block();
     log_open_block("Importing user history...");
     $this->_query("SELECT * from users");
     $this->_create_actions('user', 'project_actions');
     log_close_block();
 }
 protected function _execute()
 {
     log_open_block("Adding version info table");
     $this->_query("CREATE TABLE `versions` (`title` VARCHAR( 100 ) NOT NULL ,`version` VARCHAR( 50 ) NOT NULL);");
     log_close_block();
 }
 protected function _execute()
 {
     log_open_block("Updating summary in folders");
     $this->_update_folders('news_folders');
     log_close_block();
 }