classes/Tools/BatchTool.php
public function startAction() {
        $posts = $this->getImportBatch(-1);

        if($posts['total'] > 0) {
            try {
                $postIDs = [];
                foreach($posts['posts'] as $post) {
                    $postIDs[] = $post['id'];
                }

                BatchManager::instance()->addToBatchAndRun($this->batchIdentifier(), $postIDs);
            } catch (\Exception $ex) {
                json_response(["status"=>"error", "error" => $ex->getMessage()]);
            }
        } else {
            BatchManager::instance()->reset($this->batchIdentifier());
            json_response(['status' => 'finished']);
        }

        $data = [
            'status' => 'running',
            'total' => $posts['total'],
            'first' => $posts['posts'][0]
        ];

        json_response($data);
    }
public function startAction() {
        $posts = $this->getImportBatch(-1);

        if($posts['total'] > 0) {
            try {
                $postIDs = [];
                foreach($posts['posts'] as $post) {
                    $postIDs[] = $post['id'];
                }

                BatchManager::instance()->addToBatchAndRun($this->batchIdentifier(), $postIDs);
            } catch (\Exception $ex) {
                json_response(["status"=>"error", "error" => $ex->getMessage()]);
            }
        } else {
            BatchManager::instance()->reset($this->batchIdentifier());
            json_response(['status' => 'finished']);
        }

        $data = [
            'status' => 'running',
            'total' => $posts['total'],
            'first' => $posts['posts'][0]
        ];

        json_response($data);
    }
public function startAction ( ) { $ posts = $ this -> getImportBatch ( - 1 ) ; if ( $ posts [ 'total' ] > 0 ) { try { $ postIDs = [ ] ; foreach ( $ posts [ 'posts' ] as $ post ) { $ postIDs [ ] = $ post [ 'id' ] ; } BatchManager :: instance ( ) -> addToBatchAndRun ( $ this -> batchIdentifier ( ) , $ postIDs ) ; } catch ( \ Exception $ ex ) { json_response ( [ "status" => "error" , "error" => $ ex -> getMessage ( ) ] ) ; } } else { BatchManager :: instance ( ) -> reset ( $ this -> batchIdentifier ( ) ) ; json_response ( [ 'status' => 'finished' ] ) ; } $ data = [ 'status' => 'running' , 'total' => $ posts [ 'total' ] , 'first' => $ posts [ 'posts' ] [ 0 ] ] ; json_response ( $ data ) ; }
The action that starts a batch in motion
The action that starts a batch in motion