public function run($request)
 {
     // update block/set titles
     // Name field has been reverted back to Title
     // DB::query("update Block set Name = Title");
     // DB::query("update BlockSet set Name = Title");
     // update block areas
     DB::query("\n\t\t\tupdate SiteTree_Blocks\n\t\t\tleft join Block on SiteTree_Blocks.BlockID = Block.ID\n\t\t\tset BlockArea = Block.Area\n\t\t\twhere BlockID = Block.ID\n\t\t");
     // update block sort
     DB::query("\n\t\t\tupdate SiteTree_Blocks\n\t\t\tleft join Block on SiteTree_Blocks.BlockID = Block.ID\n\t\t\tset Sort = Block.Weight\n\t\t\twhere BlockID = Block.ID\n\t\t");
     echo "BlockAreas, Sort updated<br />";
     // migrate global blocks
     $sc = SiteConfig::current_site_config();
     if ($sc->Blocks()->Count()) {
         $set = BlockSet::get()->filter('Title', 'Global')->first();
         if (!$set) {
             $set = BlockSet::create(array('Title' => 'Global'));
             $set->write();
         }
         foreach ($sc->Blocks() as $block) {
             if (!$set->Blocks()->find('ID', $block->ID)) {
                 $set->Blocks()->add($block, array('Sort' => $block->Weight, 'BlockArea' => $block->Area));
                 echo "Block #{$block->ID} added to Global block set<br />";
             }
         }
     }
     // publish blocks
     $blocks = Block::get()->filter('Published', 1);
     foreach ($blocks as $block) {
         $block->publish('Stage', 'Live');
         echo "Published Block #{$block->ID}<br />";
     }
 }
 /**
  * Get Any BlockSets that apply to this page.
  *
  * @return ArrayList
  * */
 public function getAppliedSets()
 {
     $list = ArrayList::create();
     if (!$this->owner->InheritBlockSets) {
         return $list;
     }
     $sets = BlockSet::get()->where("(PageTypesValue IS NULL) OR (PageTypesValue LIKE '%:\"{$this->owner->ClassName}%')");
     $ancestors = $this->owner->getAncestors()->column('ID');
     foreach ($sets as $set) {
         $restrictedToParerentIDs = $set->PageParents()->column('ID');
         if (count($restrictedToParerentIDs)) {
             // check whether the set should include selected parent, in which case check whether
             // it was in the restricted parents list. If it's not, or if include parentpage
             // wasn't selected, we check the ancestors of this page.
             if ($set->IncludePageParent && in_array($this->owner->ID, $restrictedToParerentIDs)) {
                 $list->add($set);
             } else {
                 if (count($ancestors)) {
                     foreach ($ancestors as $ancestor) {
                         if (in_array($ancestor, $restrictedToParerentIDs)) {
                             $list->add($set);
                             continue;
                         }
                     }
                 }
             }
         } else {
             $list->add($set);
         }
     }
     return $list;
 }