src/Shell/ImportShell.php
protected function createImportResults(Import $import, int $count) : void
    {
        $this->out('Preparing records ..');

        $progress = $this->helper('Progress');
        Assert::isInstanceOf($progress, ProgressHelper::class);
        $progress->init();

        $table = TableRegistry::get('CsvMigrations.ImportResults');
        Assert::isInstanceOf($table, ImportResultsTable::class);

        $query = $table->find('all')->where(['import_id' => $import->get('id')]);
        $queryCount = $query->count();

        if ($queryCount >= $count) {
            return;
        }

        $data = [
            'import_id' => $import->get('id'),
            'status' => $table::STATUS_PENDING,
            'status_message' => $table::STATUS_PENDING_MESSAGE,
            'model_name' => $import->get('model_name')
        ];

        $i = $queryCount + 1;
        $progressCount = $count - $queryCount;
        // set $i = 1 to skip header row
        for ($i; $i <= $count; $i++) {
            $data['row_number'] = $i;

            $entity = $table->newEntity();
            $entity = $table->patchEntity($entity, $data);

            $table->save($entity);

            $progress->increment(100 / $progressCount);
            $progress->draw();
        }

        $this->out(null);
    }
protected function createImportResults(Import $import, int $count) : void
    {
        $this->out('Preparing records ..');

        $progress = $this->helper('Progress');
        Assert::isInstanceOf($progress, ProgressHelper::class);
        $progress->init();

        $table = TableRegistry::get('CsvMigrations.ImportResults');
        Assert::isInstanceOf($table, ImportResultsTable::class);

        $query = $table->find('all')->where(['import_id' => $import->get('id')]);
        $queryCount = $query->count();

        if ($queryCount >= $count) {
            return;
        }

        $data = [
            'import_id' => $import->get('id'),
            'status' => $table::STATUS_PENDING,
            'status_message' => $table::STATUS_PENDING_MESSAGE,
            'model_name' => $import->get('model_name')
        ];

        $i = $queryCount + 1;
        $progressCount = $count - $queryCount;
        // set $i = 1 to skip header row
        for ($i; $i <= $count; $i++) {
            $data['row_number'] = $i;

            $entity = $table->newEntity();
            $entity = $table->patchEntity($entity, $data);

            $table->save($entity);

            $progress->increment(100 / $progressCount);
            $progress->draw();
        }

        $this->out(null);
    }
protected function createImportResults ( Import $ import , int $ count ) : void { $ this -> out ( 'Preparing records ..' ) ; $ progress = $ this -> helper ( 'Progress' ) ; Assert :: isInstanceOf ( $ progress , ProgressHelper :: class ) ; $ progress -> init ( ) ; $ table = TableRegistry :: get ( 'CsvMigrations.ImportResults' ) ; Assert :: isInstanceOf ( $ table , ImportResultsTable :: class ) ; $ query = $ table -> find ( 'all' ) -> where ( [ 'import_id' => $ import -> get ( 'id' ) ] ) ; $ queryCount = $ query -> count ( ) ; if ( $ queryCount >= $ count ) { return ; } $ data = [ 'import_id' => $ import -> get ( 'id' ) , 'status' => $ table :: STATUS_PENDING , 'status_message' => $ table :: STATUS_PENDING_MESSAGE , 'model_name' => $ import -> get ( 'model_name' ) ] ; $ i = $ queryCount + 1 ; $ progressCount = $ count - $ queryCount ; // set $i = 1 to skip header row for ( $ i ; $ i <= $ count ; $ i ++ ) { $ data [ 'row_number' ] = $ i ; $ entity = $ table -> newEntity ( ) ; $ entity = $ table -> patchEntity ( $ entity , $ data ) ; $ table -> save ( $ entity ) ; $ progress -> increment ( 100 / $ progressCount ) ; $ progress -> draw ( ) ; } $ this -> out ( null ) ; }
Import results generator.

@param \CsvMigrations\Model\Entity\Import $import Import entity
@param int $count Progress count
@return void
Import results generator .