Exemple #1
0
 /**
  * Save a DAO to the data store
  *
  * @param IDao $dao
  *
  * @return array of changed properties
  *
  * @throws DataStoreException
  */
 public function save(IDao $dao)
 {
     $dao = $this->_verifyDao($dao);
     if (!$this->_getDaoChanges($dao)) {
         return [];
     }
     $statement = $this->_getStatement($dao);
     if (!$statement instanceof IStatement) {
         return [];
     }
     $this->_prepareQuery($statement, $dao);
     $assembler = $this->_assemble($statement);
     $connection = $this->_connectedConnection();
     $connection->runQuery($assembler->getQuery(), $assembler->getParameters());
     if (!$this->_hasIds($dao) && $connection instanceof ILastInsertId) {
         $ids = $dao->getDaoIDProperties();
         foreach ($ids as $idField) {
             $id = $connection->getLastInsertId($idField);
             if (!empty($id)) {
                 $dao->setDaoProperty($idField, $id);
             }
         }
     }
     $changes = $dao->getDaoChanges();
     $dao->resetCounters();
     parent::save($dao);
     return $changes;
 }
Exemple #2
0
 /**
  * Save a file to the filesystem
  *
  * @param IDao $dao
  *
  * @return array of changed properties
  *
  * @throws DataStoreException
  */
 public function save(IDao $dao)
 {
     $dao = $this->_verifyDao($dao);
     file_put_contents($dao->filepath, $dao->getPropertySerialized('content', $dao->content));
     $changes = $dao->getDaoChanges();
     parent::save($dao);
     return $changes;
 }