Unable to move block from one page to another

Permalink
Hi all!

I face some problems moving certain blocks from one page to another.
Within my custom view template I retrieve all
blocks of one area and try to move them to another page's area if they are beyond a certain age.
On the first try I worked partially (not all blocks had been moved). On the target page the blocks where shown correctly, but vanished after a refresh of the page.

My code schematically:

<in custom view template>
$a = new Area(MAIN_AREA);
$a->display($c);
$pageArchive = Page::getByPath('/archive');
for ($i=count($blocks)-1; $i>=0; $i--)
{
  $b = $block[$i];
  if (<check_age>)
  {
    $a = Area::getOrCreate($pageArchive, MAIN_AREA);
    $b->move($pageArchive, $a);
  }
}


Maybe, I am missing some important point here?

 
Mnkras replied on at Permalink Reply
Mnkras
does MAIN_AREA = Main?

just make it

$a = new Area('Main');

it avoids confusion
'
also this shouldn't be done in a custom template but a job,

http://www.concrete5.org/documentation/developers/system/jobs/...