public function save(\Tx_Oelib_Model $model)
    {
        if ($this->isModelAMemoryOnlyDummy($model)) {
            throw new \InvalidArgumentException(
                'This model is a memory-only dummy that must not be saved.',
                1331319682
            );
        }

        if (!$this->hasDatabaseAccess()
            || !$model->isDirty()
            || !$model->isLoaded()
            || $model->isReadOnly()
        ) {
            return;
        }

        $data = $this->getPreparedModelData($model);
        $this->cacheModelByKeys($model, $data);

        if ($model->hasUid()) {
            \Tx_Oelib_Db::update($this->getTableName(), 'uid = ' . $model->getUid(), $data);
            $this->deleteManyToManyRelationIntermediateRecords($model);
        } else {
            $this->prepareDataForNewRecord($data);
            $model->setUid(\Tx_Oelib_Db::insert($this->getTableName(), $data));
            $this->map->add($model);
        }

        if ($model->isDeleted()) {
            $model->markAsDead();
        } else {
            $model->markAsClean();
            // We save the 1:n relations after marking this model as clean
            // in order to avoid infinite loops when the foreign model tries
            // to save this parent.
            $this->saveOneToManyRelationRecords($model);
            $this->createManyToManyRelationIntermediateRecords($model);
        }
    }
public function save(\Tx_Oelib_Model $model)
    {
        if ($this->isModelAMemoryOnlyDummy($model)) {
            throw new \InvalidArgumentException(
                'This model is a memory-only dummy that must not be saved.',
                1331319682
            );
        }

        if (!$this->hasDatabaseAccess()
            || !$model->isDirty()
            || !$model->isLoaded()
            || $model->isReadOnly()
        ) {
            return;
        }

        $data = $this->getPreparedModelData($model);
        $this->cacheModelByKeys($model, $data);

        if ($model->hasUid()) {
            \Tx_Oelib_Db::update($this->getTableName(), 'uid = ' . $model->getUid(), $data);
            $this->deleteManyToManyRelationIntermediateRecords($model);
        } else {
            $this->prepareDataForNewRecord($data);
            $model->setUid(\Tx_Oelib_Db::insert($this->getTableName(), $data));
            $this->map->add($model);
        }

        if ($model->isDeleted()) {
            $model->markAsDead();
        } else {
            $model->markAsClean();
            // We save the 1:n relations after marking this model as clean
            // in order to avoid infinite loops when the foreign model tries
            // to save this parent.
            $this->saveOneToManyRelationRecords($model);
            $this->createManyToManyRelationIntermediateRecords($model);
        }
    }
public function save ( \ Tx_Oelib_Model $ model ) { if ( $ this -> isModelAMemoryOnlyDummy ( $ model ) ) { throw new \ InvalidArgumentException ( 'This model is a memory-only dummy that must not be saved.' , 1331319682 ) ; } if ( ! $ this -> hasDatabaseAccess ( ) || ! $ model -> isDirty ( ) || ! $ model -> isLoaded ( ) || $ model -> isReadOnly ( ) ) { return ; } $ data = $ this -> getPreparedModelData ( $ model ) ; $ this -> cacheModelByKeys ( $ model , $ data ) ; if ( $ model -> hasUid ( ) ) { \ Tx_Oelib_Db :: update ( $ this -> getTableName ( ) , 'uid = ' . $ model -> getUid ( ) , $ data ) ; $ this -> deleteManyToManyRelationIntermediateRecords ( $ model ) ; } else { $ this -> prepareDataForNewRecord ( $ data ) ; $ model -> setUid ( \ Tx_Oelib_Db :: insert ( $ this -> getTableName ( ) , $ data ) ) ; $ this -> map -> add ( $ model ) ; } if ( $ model -> isDeleted ( ) ) { $ model -> markAsDead ( ) ; } else { $ model -> markAsClean ( ) ; // We save the 1:n relations after marking this model as clean // in order to avoid infinite loops when the foreign model tries // to save this parent. $ this -> saveOneToManyRelationRecords ( $ model ) ; $ this -> createManyToManyRelationIntermediateRecords ( $ model ) ; } }
Writes a model to the database. Does nothing if database access is
denied, if the model is clean, if the model has status dead, virgin or
ghost, if the model is read-only or if there is no data to set.

@param \Tx_Oelib_Model $model the model to write to the database

@return void
Writes a model to the database . Does nothing if database access is denied if the model is clean if the model has status dead virgin or ghost if the model is read - only or if there is no data to set .