public function process()
    {
        $remainingChildren = $this->remainingChildren;

        // if there's no more, we're done!
        if (!count($remainingChildren)) {
            $this->isComplete = true;
            return;
        }

        // we need to always increment! This is important, because if we don't then our container
        // that executes around us thinks that the job has died, and will stop it running.
        $this->currentStep++;

        // lets process our first item - note that we take it off the list of things left to do
        $ID = array_shift($remainingChildren);

        // get the page
        $page = DataObject::get_by_id(Page::class, $ID);
        if ($page) {
            // publish it
            $page->doPublish();

            // and add its children to the list to be published
            foreach ($page->Children() as $child) {
                $remainingChildren[] = $child->ID;
                // we increase how many steps we need to do - this means our total steps constantly rises,
                // but it gives users an idea of exactly how many more we know about
                $this->totalSteps++;
            }
            $page->destroy();
            unset($page);
        }

        // and now we store the new list of remaining children
        $this->remainingChildren = $remainingChildren;

        if (!count($remainingChildren)) {
            $this->isComplete = true;
            return;
        }
    }
public function process()
    {
        $remainingChildren = $this->remainingChildren;

        // if there's no more, we're done!
        if (!count($remainingChildren)) {
            $this->isComplete = true;
            return;
        }

        // we need to always increment! This is important, because if we don't then our container
        // that executes around us thinks that the job has died, and will stop it running.
        $this->currentStep++;

        // lets process our first item - note that we take it off the list of things left to do
        $ID = array_shift($remainingChildren);

        // get the page
        $page = DataObject::get_by_id(Page::class, $ID);
        if ($page) {
            // publish it
            $page->doPublish();

            // and add its children to the list to be published
            foreach ($page->Children() as $child) {
                $remainingChildren[] = $child->ID;
                // we increase how many steps we need to do - this means our total steps constantly rises,
                // but it gives users an idea of exactly how many more we know about
                $this->totalSteps++;
            }
            $page->destroy();
            unset($page);
        }

        // and now we store the new list of remaining children
        $this->remainingChildren = $remainingChildren;

        if (!count($remainingChildren)) {
            $this->isComplete = true;
            return;
        }
    }
public function process ( ) { $ remainingChildren = $ this -> remainingChildren ; // if there's no more, we're done! if ( ! count ( $ remainingChildren ) ) { $ this -> isComplete = true ; return ; } // we need to always increment! This is important, because if we don't then our container // that executes around us thinks that the job has died, and will stop it running. $ this -> currentStep ++ ; // lets process our first item - note that we take it off the list of things left to do $ ID = array_shift ( $ remainingChildren ) ; // get the page $ page = DataObject :: get_by_id ( Page :: class , $ ID ) ; if ( $ page ) { // publish it $ page -> doPublish ( ) ; // and add its children to the list to be published foreach ( $ page -> Children ( ) as $ child ) { $ remainingChildren [ ] = $ child -> ID ; // we increase how many steps we need to do - this means our total steps constantly rises, // but it gives users an idea of exactly how many more we know about $ this -> totalSteps ++ ; } $ page -> destroy ( ) ; unset ( $ page ) ; } // and now we store the new list of remaining children $ this -> remainingChildren = $ remainingChildren ; if ( ! count ( $ remainingChildren ) ) { $ this -> isComplete = true ; return ; } }
Lets process a single node, and publish it if necessary
Lets process a single node and publish it if necessary