Ejemplo n.º 1
0
 protected function execute($arguments = array(), $options = array())
 {
     // We need a proper environment. This also gives us superadmin privileges
     aTaskTools::signinAsTaskUser($this->createConfiguration($options['application'], $options['env']), $options['connection']);
     aTaskTools::setCliHost();
     // Get all of the current pages with their slots. For efficiency this normally does not return slots
     // that are not the current version
     if ($options['allversions']) {
         // All versions case is a simpler query since we want to look at every slot
         $slots = Doctrine::getTable('aSlot')->findAll();
         foreach ($slots as $slot) {
             $slot->refreshSlot();
         }
     } else {
         // All cultures
         $pages = aPageTable::queryWithSlots(false, 'all')->execute();
         foreach ($pages as $page) {
             foreach ($page->Areas as $area) {
                 foreach ($area->AreaVersions as $areaVersion) {
                     foreach ($areaVersion->AreaVersionSlots as $areaVersionSlot) {
                         $areaVersionSlot->Slot->refreshSlot();
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * DOCUMENT ME
  * @param mixed $args
  * @param mixed $options
  */
 protected function execute($args = array(), $options = array())
 {
     aTaskTools::signinAsTaskUser($this->configuration, $options['connection']);
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getDoctrineConnection();
     if (!$this->askConfirmation("Importing any content will erase any existing content, are you sure? [y/N]", 'QUESTION_LARGE', false)) {
         die("Import CANCELLED.  No changes made.\n");
     }
     if (is_null($options['file'])) {
         $rootDir = $this->configuration->getRootDir();
         $dataDir = $rootDir . '/data/a';
         $options['file'] = $dataDir . '/site.xml';
         $options['pages'] = $dataDir . '/pages';
         $options['images'] = $dataDir . '/images';
     }
     $importer = new aImporter($connection, array('xmlFile' => $options['file'], 'pagesDir' => $options['pages'], 'imagesDir' => $options['images']));
     $importer->import();
 }
Ejemplo n.º 3
0
 protected function execute($args = array(), $options = array())
 {
     aTaskTools::signinAsTaskUser($this->configuration, $options['connection']);
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getDoctrineConnection();
     if (is_null($options['posts']) && is_null($options['events'])) {
         die("You must specify at least one of the posts and events options with a path to the xml file.\n");
     }
     if (!$this->askConfirmation("Importing the same content twice will result in duplicate content, are you sure? [y/N]", 'QUESTION_LARGE', false)) {
         die("Import CANCELLED.  No changes made.\n");
     }
     $rootDir = $this->configuration->getRootDir();
     $importer = new aBlogImporter($connection, $options);
     if (!is_null($options['events'])) {
         $importer->import('events');
     }
     if (!is_null($options['posts'])) {
         $importer->import('posts');
     }
 }
 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');
     }
 }