Ejemplo n.º 1
0
 /**
  * If culture is null you get the current user's culture,
  * or sf_default_culture if none is set or we're running in a task context
  * @param mixed $slug
  * @param mixed $culture
  * @return mixed
  */
 public static function retrieveBySlugWithSlots($slug, $culture = null)
 {
     if (is_null($culture)) {
         $culture = aTools::getUserCulture();
     }
     $query = aPageTable::queryWithSlots(false, $culture);
     $pageInfo = null;
     if (sfConfig::get('app_a_fasthydrate', false)) {
         $pageInfo = $query->andWhere('p.slug = ?', $slug)->fetchOne(array(), Doctrine::HYDRATE_ARRAY);
         if ($pageInfo) {
             $page = new aPage();
             $page->hydrate($pageInfo);
         } else {
             $page = null;
         }
     } else {
         $page = $query->andWhere('p.slug = ?', $slug)->fetchOne();
     }
     if ($page) {
         // In case Doctrine is clever and returns the same page object
         $page->clearSlotCache();
         $page->setCulture($culture);
         // Cheap hydration of the slots happens here
         $page->populateSlotCache($pageInfo['Areas']);
     }
     return $page;
 }
 /**
  * Listener to setup blog item and its virtual page
  * @param <type> $event
  */
 public function postInsert($event)
 {
     // Create a virtual page for this item
     $page = new aPage();
     $page['slug'] = $this->getVirtualPageSlug();
     // Search is good, let it happen
     $page['view_is_secure'] = false;
     // ... But not if we're unpublished
     $page->archived = !($this->status === 'published');
     $page->save();
     $this->Page = $page;
     // Create a slot for the title and add to the virtual page
     $title = $page->createSlot('aText');
     $title->value = 'Untitled';
     $title->save();
     $page->newAreaVersion('title', 'add', array('permid' => 1, 'slot' => $title));
     // Create a slot to index the tags and categories in search.
     $catTag = $page->createSlot('aText');
     $catTag->value = '';
     $catTag->save();
     $page->newAreaVersion('catTag', 'add', array('permid' => 1, 'slot' => $catTag));
     // Make default values for this item
     $this['slug'] = 'untitled-' . $this['id'];
     $this['title'] = 'untitled';
     $this['slug_saved'] = false;
     // This prevents post preupdate from running after the next save
     $this->update = false;
     $this->save();
 }
Ejemplo n.º 3
0
 /**
  * If you are making a new page pass a new page object and set $parent also.
  * To edit an existing page, just set $page and leave $parent null.
  * At least one must not be null for normal use, but both can be null for
  * ai18nupdate
  * @param mixed $page
  * @param mixed $parent
  */
 public function __construct($page = null, $parent = null)
 {
     if (!$page) {
         $page = new aPage();
         if (!$parent) {
             echo "Creating parent object, this does not make sense unless you are running ai18nupdate\n";
             $parent = new aPage();
         }
     }
     if ($page->isNew()) {
         $this->parent = $parent;
         $this->new = true;
     }
     parent::__construct($page);
     if ($this->getObject()->isNew()) {
         $slug = $this->parent->slug;
         if (substr($slug, -1, 1) !== '/') {
             $slug .= '/';
         }
         $this->getWidget('slug')->setDefault($slug);
     }
 }
 public function executeCreate()
 {
     $this->flunkUnless($this->getRequest()->getMethod() == sfRequest::POST);
     $parent = $this->retrievePageForEditingBySlugParameter('parent', 'manage');
     $title = trim($this->getRequestParameter('title'));
     $this->flunkUnless(strlen($title));
     $pathComponent = aTools::slugify($title, false);
     $base = $parent->getSlug();
     if ($base === '/') {
         $base = '';
     }
     $slug = "{$base}/{$pathComponent}";
     $page = new aPage();
     $page->setArchived(!sfConfig::get('app_a_default_on', true));
     $page->setSlug($slug);
     $existingPage = aPageTable::retrieveBySlug($slug);
     if ($existingPage) {
         // TODO: an error in addition to displaying the existing page?
         return $this->redirect($existingPage->getUrl());
     } else {
         $page->getNode()->insertAsFirstChildOf($parent);
         // Figure out what template this new page should use based on
         // the template rules.
         //
         // The default rule assigns default to everything.
         $rule = aRules::select(sfConfig::get('app_a_template_rules', array(array('rule' => '*', 'template' => 'default'))), $slug);
         if (!$rule) {
             $template = 'default';
         } else {
             $template = $rule['template'];
         }
         $page->template = $template;
         // Must save the page BEFORE we call setTitle, which has the side effect of
         // refreshing the page object
         $page->save();
         $page->setTitle(htmlspecialchars($title));
         return $this->redirect($page->getUrl());
     }
 }
Ejemplo n.º 5
0
 public static function setPageEnvironment(sfAction $action, aPage $page)
 {
     // Title is pre-escaped as valid HTML
     $prefix = aTools::getOptionI18n('title_prefix');
     $action->getResponse()->setTitle($prefix . $page->getTitle(), false);
     // Necessary to allow the use of
     // aTools::getCurrentPage() in the layout.
     // In Symfony 1.1+, you can't see $action->page from
     // the layout.
     aTools::setCurrentPage($page);
     // Borrowed from sfSimpleCMS
     if (sfConfig::get('app_a_use_bundled_layout', true)) {
         $action->setLayout(sfContext::getInstance()->getConfiguration()->getTemplateDir('a', 'layout.php') . '/layout');
     }
     // Loading the a helper at this point guarantees not only
     // helper functions but also necessary JavaScript and CSS
     sfContext::getInstance()->getConfiguration()->loadHelpers('a');
 }
 protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     // We need to use PDO here because Doctrine is more than a little confused when
     // we've renamed the codebase but not the tables
     echo "Renaming tables in database\n";
     $tables = array('pk_context_cms_slot' => 'a_slot', 'pk_context_cms_area_version_slot' => 'a_area_version_slot', 'pk_context_cms_area_version' => 'a_area_version', 'pk_context_cms_area' => 'a_area', 'pk_context_cms_page' => 'a_page', 'pk_blog_category' => 'a_blog_category', 'pk_blog_event_version' => 'a_blog_event_version', 'pk_blog_item' => 'a_blog_item', 'pk_blog_item_version' => 'a_blog_item_version', 'pk_blog_post_version' => 'a_blog_post_version', 'pk_context_cms_access' => 'a_access', 'pk_context_cms_lucene_update' => 'a_lucene_update', 'pk_media_item' => 'a_media_item');
     $conn = Doctrine_Manager::connection()->getDbh();
     foreach ($tables as $old => $new) {
         try {
             echo "before\n";
             $conn->query("RENAME TABLE {$old} TO {$new}");
             echo "after\n";
         } catch (Exception $e) {
             echo "Rename of {$old} failed, that's normal if you don't use that table's plugin or you have run this script before.\n";
         }
     }
     echo "Renaming slots and engines in database\n";
     try {
         $conn->query('UPDATE a_slot SET type = REPLACE(type, "pkContextCMS", "a")');
     } catch (Exception $e) {
         echo "Warning: unable to reset slot types in a_slot table\n";
     }
     try {
         $conn->query('UPDATE a_page SET engine = REPLACE(engine, "pk", "a")');
     } catch (Exception $e) {
         echo "Warning: unable to rename engines in a_page table\n";
     }
     try {
         $conn->query('ALTER TABLE a_page ADD admin tinyint(1)');
     } catch (Exception $e) {
         echo "Warning: unable to add admin column to a_page table\n";
     }
     try {
         $conn->query('ALTER TABLE a_slot ADD variant varchar(100)');
     } catch (Exception $e) {
         echo "Warning: unable to add variant column to a_slot table\n";
     }
     try {
         $conn->query("CREATE TABLE `a_slot_media_item` (\n        `media_item_id` int(11) NOT NULL DEFAULT '0',\n        `slot_id` int(11) NOT NULL DEFAULT '0',\n        PRIMARY KEY (`media_item_id`,`slot_id`),\n        KEY `a_slot_media_item_slot_id_a_slot_id` (`slot_id`),\n        CONSTRAINT `a_slot_media_item_media_item_id_a_media_item_id` FOREIGN KEY (`media_item_id`) REFERENCES `a_media_item` (`id`) ON DELETE CASCADE,\n        CONSTRAINT `a_slot_media_item_slot_id_a_slot_id` FOREIGN KEY (`slot_id`) REFERENCES `a_slot` (`id`) ON DELETE CASCADE\n      ) ENGINE=InnoDB DEFAULT CHARSET=latin1;");
     } catch (Exception $e) {
         echo "Warning: couldn't create a_slot_media_item table\n";
     }
     echo "Migrating media slots\n";
     $count = 0;
     $mediaSlots = Doctrine::getTable('aSlot')->createQuery('s')->whereIn('s.type', array('aImage', 'aPDF', 'aButton', 'aSlideshow', 'aVideo'))->execute();
     $total = count($mediaSlots);
     foreach ($mediaSlots as $mediaSlot) {
         $count++;
         echo "Migrating slot {$count} of {$total}\n";
         if ($mediaSlot->type === 'aSlideshow') {
             $items = $mediaSlot->getArrayValue();
             if (isset($items[0]) && isset($items[0]->id)) {
                 $order = array();
                 foreach ($items as $item) {
                     // aArray::getids has trouble with StdClass objects for some reason
                     $order[] = $item->id;
                 }
                 $mediaSlot->unlink('MediaItems');
                 $mediaSlot->link('MediaItems', $order);
                 $mediaSlot->setArrayValue(array('order' => $order));
                 $mediaSlot->save();
             }
         } else {
             if (strlen($mediaSlot->value)) {
                 $item = unserialize($mediaSlot->value);
                 if (isset($item->id)) {
                     $mediaSlot->unlink('MediaItems');
                     $mediaSlot->link('MediaItems', array($item->id));
                     $mediaSlot->setValue(null);
                     $mediaSlot->save();
                 }
             }
         }
     }
     try {
         $conn->query("CREATE TABLE `a_media_category` (\n        `id` int(11) NOT NULL AUTO_INCREMENT,\n        `name` varchar(255) DEFAULT NULL,\n        `description` text,\n        `created_at` datetime NOT NULL,\n        `updated_at` datetime NOT NULL,\n        `slug` varchar(255) DEFAULT NULL,\n        PRIMARY KEY (`id`),\n        UNIQUE KEY `name` (`name`)\n      ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1");
     } catch (Exception $e) {
         echo "Warning: couldn't create a_media_category table\n";
     }
     try {
         $conn->query("CREATE TABLE `a_media_item_category` (\n        `media_item_id` int(11) NOT NULL DEFAULT '0',\n        `media_category_id` int(11) NOT NULL DEFAULT '0',\n        PRIMARY KEY (`media_item_id`,`media_category_id`),\n        KEY `a_media_item_category_media_category_id_a_media_category_id` (`media_category_id`),\n        CONSTRAINT `a_media_item_category_media_category_id_a_media_category_id` FOREIGN KEY (`media_category_id`) REFERENCES `a_media_category` (`id`) ON DELETE CASCADE,\n        CONSTRAINT `a_media_item_category_media_item_id_a_media_item_id` FOREIGN KEY (`media_item_id`) REFERENCES `a_media_item` (`id`) ON DELETE CASCADE\n      ) ENGINE=InnoDB DEFAULT CHARSET=latin1");
     } catch (Exception $e) {
         echo "Warning: couldn't create a_media_item_category table\n";
     }
     try {
         $conn->query("CREATE TABLE `a_media_page_category` (\n        `page_id` int(11) NOT NULL DEFAULT '0',\n        `media_category_id` int(11) NOT NULL DEFAULT '0',\n        PRIMARY KEY (`page_id`,`media_category_id`),\n        KEY `a_media_page_category_media_category_id_a_media_category_id` (`media_category_id`),\n        CONSTRAINT `a_media_page_category_media_category_id_a_media_category_id` FOREIGN KEY (`media_category_id`) REFERENCES `a_media_category` (`id`) ON DELETE CASCADE,\n        CONSTRAINT `a_media_page_category_page_id_a_page_id` FOREIGN KEY (`page_id`) REFERENCES `a_page` (`id`) ON DELETE CASCADE\n      ) ENGINE=InnoDB DEFAULT CHARSET=latin1");
     } catch (Exception $e) {
         echo "Warning: couldn't create a_media_page_category table\n";
     }
     echo "Rebuilding search index\n";
     $cmd = "./symfony apostrophe:rebuild-search-index --env=" . $options['env'];
     system($cmd, $result);
     if ($result != 0) {
         die("Unable to rebuild search indexes\n");
     }
     echo "If you have folders in data/pk_writable other than tmp and the zend search indexes \nyou may want to move them to data/a_writable. Due to interactions with svn this is not\nautomatic. In our projects we use svn ignore rules to protect the contents of the\ndata/*_writable folder. This is primarily an issue on servers other than your\ndevelopment machine, where you run this task separately. On your development\nmachine pk_writable is renamed to a_writable automatically.\n";
     // We need to be an admin user so the model layer sees the current user has
     // permissions to do what follows. We can't do this any earlier because
     // the routing table fires up and routes the home page which requires looking
     // at some engine routes, so the a_page table has to be ready
     aTaskTools::signinAsTaskUser($this->createConfiguration($options['application'], $options['env']));
     // Create the admin pages
     $home = aPageTable::retrieveBySlug('/');
     $admin = aPageTable::retrieveBySlug('/admin');
     if (!$admin) {
         $admin = new aPage();
         $admin->setSlug('/admin');
         $admin->setAdmin(true);
         $admin->getNode()->insertAsFirstChildOf($home);
         $admin->setEngine('aAdmin');
         $admin->save();
         // Must save the page BEFORE we call setTitle, which has the side effect of
         // refreshing the page object
         $admin->setTitle('Admin');
     }
     $page = aPageTable::retrieveBySlug('/admin/media');
     if (!$page) {
         $page = new aPage();
         $page->setSlug('/admin/media');
         $page->setAdmin(true);
         $page->getNode()->insertAsLastChildOf($admin);
         $page->setEngine('aMedia');
         $page->save();
         // Must save the page BEFORE we call setTitle, which has the side effect of
         // refreshing the page object
         $page->setTitle('Media');
     }
 }
Ejemplo n.º 7
0
 /**
  * DOCUMENT ME
  * @param mixed $arguments
  * @param mixed $options
  */
 protected function execute($arguments = array(), $options = array())
 {
     // We need a basic context so we can notify events
     $context = sfContext::createInstance($this->configuration);
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     $postTasks = array();
     echo "\nApostrophe Database Migration Task\n  \nThis task will make any necessary database schema changes to bring your \nMySQL database up to date with the current release of Apostrophe and any additional\nApostrophe plugins that you have installed. For other databases see the source code \nor run './symfony doctrine:build-sql' to obtain the SQL commands you may need.\n  \nBACK UP YOUR DATABASE BEFORE YOU RUN THIS TASK. It works fine in our tests, \nbut why take chances with your data?\n\n";
     if (!$options['force']) {
         if (!$this->askConfirmation("Are you sure you are ready to migrate your project? [y/N]", 'QUESTION_LARGE', false)) {
             die("Operation CANCELLED. No changes made.\n");
         }
     }
     $this->migrate = new aMigrate(Doctrine_Manager::connection()->getDbh());
     // If I needed to I could look for the constraint definition like this.
     // But since we added these in the same migration I don't have to. Keep this
     // comment around as sooner or later we'll probably need to check for this
     // kind of thing
     //
     // $createTable = $data[0]['Create Table'];
     // if (!preg_match('/CONSTRAINT `a_redirect_page_id_a_page_id`/', $createTable))
     // {
     //
     // }
     if (!$this->migrate->tableExists('a_redirect')) {
         $this->migrate->sql(array("CREATE TABLE IF NOT EXISTS a_redirect (id INT AUTO_INCREMENT, page_id INT, slug VARCHAR(255) UNIQUE, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX slugindex_idx (slug), INDEX page_id_idx (page_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB;", "ALTER TABLE a_redirect ADD CONSTRAINT a_redirect_page_id_a_page_id FOREIGN KEY (page_id) REFERENCES a_page(id) ON DELETE CASCADE;"));
     }
     if (!$this->migrate->columnExists('a_media_item', 'lucene_dirty')) {
         $this->migrate->sql(array("ALTER TABLE a_media_item ADD COLUMN lucene_dirty BOOLEAN DEFAULT false;"));
     }
     if (!$this->migrate->getCommandsRun()) {
         echo "Your database is already up to date.\n\n";
     } else {
         echo $this->migrate->getCommandsRun() . " SQL commands were run.\n\n";
     }
     if (!$this->migrate->tableExists('a_group_access')) {
         // They don't have a group access table yet. In theory, they don't have an editor permission
         // to grant to groups yet either. However that is a likely name for them to invent on their
         // own, so make sure we don't panic if there is already a permission called eidtor
         $this->migrate->sql(array('CREATE TABLE a_group_access (id BIGINT AUTO_INCREMENT, page_id INT, privilege VARCHAR(100), group_id INT, INDEX pageindex_idx (page_id), INDEX group_id_idx (group_id), PRIMARY KEY(id)) ENGINE = INNODB;', 'ALTER TABLE a_group_access ADD CONSTRAINT a_group_access_page_id_a_page_id FOREIGN KEY (page_id) REFERENCES a_page(id) ON DELETE CASCADE;', 'ALTER TABLE a_group_access ADD CONSTRAINT a_group_access_group_id_sf_guard_group_id FOREIGN KEY (group_id) REFERENCES sf_guard_group(id) ON DELETE CASCADE;', 'INSERT INTO sf_guard_permission (name, description) VALUES ("editor", "For groups that will be granted editing privileges at some point in the site") ON DUPLICATE KEY UPDATE id = id;'));
     }
     $viewLocked = sfConfig::get('app_a_view_locked_sufficient_credentials', 'view_locked');
     // If they haven't customized it make sure it exists. Some pkContextCMS sites might not have it
     if ($viewLocked === 'view_locked') {
         $permission = Doctrine::getTable('sfGuardPermission')->findOneByName($viewLocked);
         if (!$permission) {
             $permission = new sfGuardPermission();
             $permission->setName('view_locked');
             $permission->save();
             $groups = array('editor', 'admin');
             foreach ($groups as $group) {
                 $g = Doctrine::getTable('sfGuardGroup')->findOneByName($group);
                 if ($g) {
                     $pg = new sfGuardGroupPermission();
                     $pg->setGroupId($g->id);
                     $pg->setPermissionId($permission->id);
                     $pg->save();
                 }
             }
         }
     }
     if (!$this->migrate->tableExists('a_category') || !$this->migrate->tableExists('a_category_group')) {
         $this->migrate->sql(array("CREATE TABLE IF NOT EXISTS a_category (id INT AUTO_INCREMENT, name VARCHAR(255) UNIQUE, description TEXT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, slug VARCHAR(255), UNIQUE INDEX a_category_sluggable_idx (slug), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB;", "CREATE TABLE IF NOT EXISTS a_category_group (category_id INT, group_id INT, PRIMARY KEY(category_id, group_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB;", "CREATE TABLE IF NOT EXISTS a_category_user (category_id INT, user_id INT, PRIMARY KEY(category_id, user_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB;", "CREATE TABLE `a_page_to_category` (\n          `page_id` INT NOT NULL DEFAULT '0',\n          `category_id` INT NOT NULL DEFAULT '0',\n          PRIMARY KEY (`page_id`,`category_id`),\n          KEY `a_page_to_category_category_id_a_category_id` (`category_id`),\n          CONSTRAINT `a_page_to_category_category_id_a_category_id` FOREIGN KEY (`category_id`) REFERENCES `a_category` (`id`) ON DELETE CASCADE,\n          CONSTRAINT `a_page_to_category_page_id_a_page_id` FOREIGN KEY (`page_id`) REFERENCES `a_page` (`id`) ON DELETE CASCADE\n        ) ENGINE=InnoDB DEFAULT CHARSET=utf8", "CREATE TABLE IF NOT EXISTS `a_media_item_to_category` (\n          `media_item_id` INT NOT NULL DEFAULT '0',\n          `category_id` INT NOT NULL DEFAULT '0',\n          PRIMARY KEY (`media_item_id`,`category_id`),\n          KEY `a_media_item_to_category_category_id_a_category_id` (`category_id`)\n        ) ENGINE=InnoDB DEFAULT CHARSET=utf8"));
         // These constraints might already be present, be tolerant
         $constraints = array("ALTER TABLE a_media_item_to_category ADD CONSTRAINT `a_media_item_to_category_category_id_a_category_id` FOREIGN KEY (`category_id`) REFERENCES `a_category` (`id`) ON DELETE CASCADE", "ALTER TABLE a_media_item_to_category ADD CONSTRAINT `a_media_item_to_category_media_item_id_a_media_item_id` FOREIGN KEY (`media_item_id`) REFERENCES `a_media_item` (`id`) ON DELETE CASCADE", "ALTER TABLE a_category_group ADD CONSTRAINT a_category_group_group_id_sf_guard_group_id FOREIGN KEY (group_id) REFERENCES sf_guard_group(id) ON DELETE CASCADE;", "ALTER TABLE a_category_group ADD CONSTRAINT a_category_group_category_id_a_category_id FOREIGN KEY (category_id) REFERENCES a_category(id) ON DELETE CASCADE;", "ALTER TABLE a_category_user ADD CONSTRAINT a_category_user_user_id_sf_guard_user_id FOREIGN KEY (user_id) REFERENCES sf_guard_user(id) ON DELETE CASCADE;", "ALTER TABLE a_category_user ADD CONSTRAINT a_category_user_category_id_a_category_id FOREIGN KEY (category_id) REFERENCES a_category(id) ON DELETE CASCADE;");
         foreach ($constraints as $c) {
             try {
                 $this->migrate->sql(array($c));
             } catch (Exception $e) {
                 echo "Error creating constraint, most likely already exists, which is OK {$c}\n";
             }
         }
         if ($this->migrate->tableExists('a_media_category')) {
             $oldCategories = $this->migrate->query('SELECT * FROM a_media_category');
         } else {
             $oldCategories = array();
         }
         $newCategories = $this->migrate->query('SELECT * FROM a_category');
         $nc = array();
         foreach ($newCategories as $newCategory) {
             $nc[$newCategory['slug']] = $newCategory;
         }
         $oldIdToNewId = array();
         echo "Migrating media categories to Apostrophe categories...\n";
         foreach ($oldCategories as $category) {
             if (isset($nc[$category['slug']])) {
                 $oldIdToNewId[$category['id']] = $nc[$category['slug']]['id'];
             } else {
                 $this->migrate->query('INSERT INTO a_category (name, description, slug) VALUES (:name, :description, :slug)', $category);
                 $oldIdToNewId[$category['id']] = $this->migrate->lastInsertId();
             }
         }
         echo "Migrating from aMediaItemCategory to aMediaItemToCategory...\n";
         $oldMappings = $this->migrate->query('SELECT * FROM a_media_item_category');
         foreach ($oldMappings as $info) {
             $info['category_id'] = $oldIdToNewId[$info['media_category_id']];
             $this->migrate->query('INSERT INTO a_media_item_to_category (media_item_id, category_id) VALUES (:media_item_id, :category_id)', $info);
         }
     }
     if (!$this->migrate->tableExists('a_embed_media_account')) {
         $this->migrate->sql(array('CREATE TABLE a_embed_media_account (id INT AUTO_INCREMENT, service VARCHAR(100) NOT NULL, username VARCHAR(100) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB;'));
     }
     if (!$this->migrate->columnExists('a_page', 'edit_admin_lock')) {
         $this->migrate->sql(array('ALTER TABLE a_page ADD COLUMN edit_admin_lock TINYINT(1) DEFAULT "0"', 'ALTER TABLE a_page ADD COLUMN view_admin_lock TINYINT(1) DEFAULT "0"'));
         $options = array('application' => $options['application'], 'env' => $options['env'], 'connection' => $options['connection']);
         $postTasks[] = array('task' => new apostropheCascadeEditPermissionsTask($this->dispatcher, $this->formatter), 'arguments' => array(), 'options' => $options);
     }
     if (!$this->migrate->columnExists('a_page', 'view_guest')) {
         $this->migrate->sql(array('ALTER TABLE a_page ADD COLUMN view_guest TINYINT(1) DEFAULT "1"'));
         $options = array('application' => $options['application'], 'env' => $options['env'], 'connection' => $options['connection']);
         $postTasks[] = array('task' => new apostropheCascadeEditPermissionsTask($this->dispatcher, $this->formatter), 'arguments' => array(), 'options' => $options);
     }
     // Migrate all IDs to BIGINT (the default in Doctrine 1.2) for compatibility with the
     // new version of sfDoctrineGuardPlugin. NOTE: we continue to use INT in create table
     // statements BEFORE this point because we need to set up relations with what they already
     // have - this call will clean that up
     $this->migrate->upgradeIds();
     // Upgrade all charsets to UTF-8 otherwise we can't store a lot of what comes back from embed services
     $this->migrate->upgradeCharsets();
     // We can add these constraints now that we have IDs of the right size
     if (!$this->migrate->constraintExists('a_media_item_to_category', 'a_media_item_to_category_category_id_a_category_id')) {
         $this->migrate->sql(array('ALTER TABLE a_media_item_to_category MODIFY COLUMN category_id BIGINT', 'ALTER TABLE a_media_item_to_category MODIFY COLUMN media_item_id BIGINT', "ALTER TABLE a_media_item_to_category ADD CONSTRAINT `a_media_item_to_category_category_id_a_category_id` FOREIGN KEY (`category_id`) REFERENCES `a_category` (`id`) ON DELETE CASCADE", "ALTER TABLE a_media_item_to_category ADD CONSTRAINT `a_media_item_to_category_media_item_id_a_media_item_id` FOREIGN KEY (`media_item_id`) REFERENCES `a_media_item` (`id`) ON DELETE CASCADE"));
     }
     // sfDoctrineGuardPlugin 5.0.x requires this
     if (!$this->migrate->columnExists('sf_guard_user', 'email_address')) {
         $this->migrate->sql(array('ALTER TABLE sf_guard_user ADD COLUMN first_name varchar(255) DEFAULT NULL', 'ALTER TABLE sf_guard_user ADD COLUMN last_name varchar(255) DEFAULT NULL', 'ALTER TABLE sf_guard_user ADD COLUMN email_address varchar(255) DEFAULT \'\''));
         // Email addresses are mandatory and can't be null. We can't start guessing whether
         // you have them in some other table or not. So the best we can do is stub in
         // the username for uniqueness for now
         $this->migrate->sql(array('UPDATE sf_guard_user SET email_address = concat(username, \'@notavalidaddress\')', 'ALTER TABLE sf_guard_user ADD UNIQUE KEY `email_address` (`email_address`);'));
     }
     if (!$this->migrate->tableExists('sf_guard_forgot_password')) {
         $this->migrate->sql(array('
     CREATE TABLE `sf_guard_forgot_password` (
       `id` bigint(20) NOT NULL AUTO_INCREMENT,
       `user_id` bigint(20) NOT NULL,
       `unique_key` varchar(255) DEFAULT NULL,
       `expires_at` datetime NOT NULL,
       `created_at` datetime NOT NULL,
       `updated_at` datetime NOT NULL,
       PRIMARY KEY (`id`),
       KEY `user_id_idx` (`user_id`),
       CONSTRAINT `sf_guard_forgot_password_user_id_sf_guard_user_id` FOREIGN KEY (`user_id`) REFERENCES `sf_guard_user` (`id`) ON DELETE CASCADE
     ) ENGINE=InnoDB DEFAULT CHARSET=utf8'));
     }
     if (!$this->migrate->columnExists('a_page', 'published_at')) {
         $this->migrate->sql(array('ALTER TABLE a_page ADD COLUMN published_at DATETIME DEFAULT NULL', 'UPDATE a_page SET published_at = created_at WHERE published_at IS NULL'));
     }
     // Remove any orphaned media items created by insufficiently carefully written embed services,
     // these can break the media repository
     $this->migrate->sql(array('DELETE FROM a_media_item WHERE type="video" AND embed IS NULL AND service_url IS NULL'));
     // Rename any tags with slashes in them to avoid breaking routes in Symfony
     $this->migrate->sql(array('UPDATE tag SET name = replace(name, "/", "-")'));
     // A chance to make plugin- and project-specific additions to the schema before Doctrine queries fail to see them
     sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($this->migrate, "a.migrateSchemaAdditions"));
     $mediaEnginePage = Doctrine::getTable('aPage')->createQuery('p')->where('p.admin IS TRUE AND p.engine = "aMedia"')->fetchOne();
     if (!$mediaEnginePage) {
         $mediaEnginePage = new aPage();
         $root = aPageTable::retrieveBySlug('/');
         $mediaEnginePage->getNode()->insertAsFirstChildOf($root);
     }
     $mediaEnginePage->slug = '/admin/media';
     $mediaEnginePage->engine = 'aMedia';
     $mediaEnginePage->setAdmin(true);
     $mediaEnginePage->setPublishedAt(aDate::mysql());
     $new = $mediaEnginePage->isNew();
     $mediaEnginePage->save();
     if ($new) {
         $mediaEnginePage->setTitle('Media');
     }
     echo "Ensured there is an admin media engine\n";
     echo "Finished updating tables.\n";
     if (count($postTasks)) {
         echo "Invoking post-migration tasks...\n";
         foreach ($postTasks as $taskInfo) {
             $taskInfo['task']->run($taskInfo['arguments'], $taskInfo['options']);
         }
     }
     echo "Done!\n";
 }