public function saveMany($entities, $options = [])
    {
        $isNew = [];
        $cleanup = function ($entities) use (&$isNew) {
            foreach ($entities as $key => $entity) {
                if (isset($isNew[$key]) && $isNew[$key]) {
                    $entity->unsetProperty($this->getPrimaryKey());
                    $entity->isNew(true);
                }
            }
        };

        try {
            $return = $this->getConnection()
                ->transactional(function () use ($entities, $options, &$isNew) {
                    foreach ($entities as $key => $entity) {
                        $isNew[$key] = $entity->isNew();
                        if ($this->save($entity, $options) === false) {
                            return false;
                        }
                    }
                });
        } catch (\Exception $e) {
            $cleanup($entities);

            throw $e;
        }

        if ($return === false) {
            $cleanup($entities);

            return false;
        }

        return $entities;
    }
public function saveMany($entities, $options = [])
    {
        $isNew = [];
        $cleanup = function ($entities) use (&$isNew) {
            foreach ($entities as $key => $entity) {
                if (isset($isNew[$key]) && $isNew[$key]) {
                    $entity->unsetProperty($this->getPrimaryKey());
                    $entity->isNew(true);
                }
            }
        };

        try {
            $return = $this->getConnection()
                ->transactional(function () use ($entities, $options, &$isNew) {
                    foreach ($entities as $key => $entity) {
                        $isNew[$key] = $entity->isNew();
                        if ($this->save($entity, $options) === false) {
                            return false;
                        }
                    }
                });
        } catch (\Exception $e) {
            $cleanup($entities);

            throw $e;
        }

        if ($return === false) {
            $cleanup($entities);

            return false;
        }

        return $entities;
    }
public function saveMany ( $ entities , $ options = [ ] ) { $ isNew = [ ] ; $ cleanup = function ( $ entities ) use ( & $ isNew ) { foreach ( $ entities as $ key => $ entity ) { if ( isset ( $ isNew [ $ key ] ) && $ isNew [ $ key ] ) { $ entity -> unsetProperty ( $ this -> getPrimaryKey ( ) ) ; $ entity -> isNew ( true ) ; } } } ; try { $ return = $ this -> getConnection ( ) -> transactional ( function ( ) use ( $ entities , $ options , & $ isNew ) { foreach ( $ entities as $ key => $ entity ) { $ isNew [ $ key ] = $ entity -> isNew ( ) ; if ( $ this -> save ( $ entity , $ options ) === false ) { return false ; } } } ) ; } catch ( \ Exception $ e ) { $ cleanup ( $ entities ) ; throw $ e ; } if ( $ return === false ) { $ cleanup ( $ entities ) ; return false ; } return $ entities ; }
Persists multiple entities of a table.

The records will be saved in a transaction which will be rolled back if
any one of the records fails to save due to failed validation or database
error.

@param \Cake\Datasource\EntityInterface[]|\Cake\Datasource\ResultSetInterface $entities Entities to save.
@param array|\ArrayAccess $options Options used when calling Table::save() for each entity.
@return bool|\Cake\Datasource\EntityInterface[]|\Cake\Datasource\ResultSetInterface False on failure, entities list on success.
@throws \Exception
Persists multiple entities of a table .