original_string: protected function _processSave($entity, $options)
      {
          $primaryColumns = (array)$this->getPrimaryKey();
  
          if ($options['checkExisting'] && $primaryColumns && $entity->isNew() && $entity->has($primaryColumns)) {
              $alias = $this->getAlias();
              $conditions = [];
              foreach ($entity->extract($primaryColumns) as $k => $v) {
                  $conditions["$alias.$k"] = $v;
              }
              $entity->isNew(!$this->exists($conditions));
          }
  
          $mode = $entity->isNew() ? RulesChecker::CREATE : RulesChecker::UPDATE;
          if ($options['checkRules'] && !$this->checkRules($entity, $mode, $options)) {
              return false;
          }
  
          $options['associated'] = $this->_associations->normalizeKeys($options['associated']);
          $event = $this->dispatchEvent('Model.beforeSave', compact('entity', 'options'));
  
          if ($event->isStopped()) {
              return $event->getResult();
          }
  
          $saved = $this->_associations->saveParents(
              $this,
              $entity,
              $options['associated'],
              ['_primary' => false] + $options->getArrayCopy()
          );
  
          if (!$saved && $options['atomic']) {
              return false;
          }
  
          $data = $entity->extract($this->getSchema()->columns(), true);
          $isNew = $entity->isNew();
  
          if ($isNew) {
              $success = $this->_insert($entity, $data);
          } else {
              $success = $this->_update($entity, $data);
          }
  
          if ($success) {
              $success = $this->_onSaveSuccess($entity, $options);
          }
  
          if (!$success && $isNew) {
              $entity->unsetProperty($this->getPrimaryKey());
              $entity->isNew(true);
          }
  
          return $success ? $entity : false;
      }
code: protected function _processSave($entity, $options)
      {
          $primaryColumns = (array)$this->getPrimaryKey();
  
          if ($options['checkExisting'] && $primaryColumns && $entity->isNew() && $entity->has($primaryColumns)) {
              $alias = $this->getAlias();
              $conditions = [];
              foreach ($entity->extract($primaryColumns) as $k => $v) {
                  $conditions["$alias.$k"] = $v;
              }
              $entity->isNew(!$this->exists($conditions));
          }
  
          $mode = $entity->isNew() ? RulesChecker::CREATE : RulesChecker::UPDATE;
          if ($options['checkRules'] && !$this->checkRules($entity, $mode, $options)) {
              return false;
          }
  
          $options['associated'] = $this->_associations->normalizeKeys($options['associated']);
          $event = $this->dispatchEvent('Model.beforeSave', compact('entity', 'options'));
  
          if ($event->isStopped()) {
              return $event->getResult();
          }
  
          $saved = $this->_associations->saveParents(
              $this,
              $entity,
              $options['associated'],
              ['_primary' => false] + $options->getArrayCopy()
          );
  
          if (!$saved && $options['atomic']) {
              return false;
          }
  
          $data = $entity->extract($this->getSchema()->columns(), true);
          $isNew = $entity->isNew();
  
          if ($isNew) {
              $success = $this->_insert($entity, $data);
          } else {
              $success = $this->_update($entity, $data);
          }
  
          if ($success) {
              $success = $this->_onSaveSuccess($entity, $options);
          }
  
          if (!$success && $isNew) {
              $entity->unsetProperty($this->getPrimaryKey());
              $entity->isNew(true);
          }
  
          return $success ? $entity : false;
      }
code_tokens: protected function _processSave ( $ entity , $ options ) { $ primaryColumns = ( array ) $ this -> getPrimaryKey ( ) ; if ( $ options [ 'checkExisting' ] && $ primaryColumns && $ entity -> isNew ( ) && $ entity -> has ( $ primaryColumns ) ) { $ alias = $ this -> getAlias ( ) ; $ conditions = [ ] ; foreach ( $ entity -> extract ( $ primaryColumns ) as $ k => $ v ) { $ conditions [ "$alias.$k" ] = $ v ; } $ entity -> isNew ( ! $ this -> exists ( $ conditions ) ) ; } $ mode = $ entity -> isNew ( ) ? RulesChecker :: CREATE : RulesChecker :: UPDATE ; if ( $ options [ 'checkRules' ] && ! $ this -> checkRules ( $ entity , $ mode , $ options ) ) { return false ; } $ options [ 'associated' ] = $ this -> _associations -> normalizeKeys ( $ options [ 'associated' ] ) ; $ event = $ this -> dispatchEvent ( 'Model.beforeSave' , compact ( 'entity' , 'options' ) ) ; if ( $ event -> isStopped ( ) ) { return $ event -> getResult ( ) ; } $ saved = $ this -> _associations -> saveParents ( $ this , $ entity , $ options [ 'associated' ] , [ '_primary' => false ] + $ options -> getArrayCopy ( ) ) ; if ( ! $ saved && $ options [ 'atomic' ] ) { return false ; } $ data = $ entity -> extract ( $ this -> getSchema ( ) -> columns ( ) , true ) ; $ isNew = $ entity -> isNew ( ) ; if ( $ isNew ) { $ success = $ this -> _insert ( $ entity , $ data ) ; } else { $ success = $ this -> _update ( $ entity , $ data ) ; } if ( $ success ) { $ success = $ this -> _onSaveSuccess ( $ entity , $ options ) ; } if ( ! $ success && $ isNew ) { $ entity -> unsetProperty ( $ this -> getPrimaryKey ( ) ) ; $ entity -> isNew ( true ) ; } return $ success ? $ entity : false ; }
docstring: Performs the actual saving of an entity based on the passed options.
  
  @param \Cake\Datasource\EntityInterface $entity the entity to be saved
  @param \ArrayObject $options the options to use for the save operation
  @return \Cake\Datasource\EntityInterface|bool
  @throws \RuntimeException When an entity is missing some of the primary keys.
  @throws \Cake\ORM\Exception\RolledbackTransactionException If the transaction
  is aborted in the afterSave event.
docstring_tokens: Performs the actual saving of an entity based on the passed options .