Example #1
0
 /**
  * Delete (a) record(s)
  *
  * @param array $where WHERE clause, specifying which records to delete
  * @return bool
  */
 public function destroy(array $where)
 {
     $where = $this->_createWhereClause($where, 'AND', false);
     try {
         /**
          * First, see if the user is allowed to update everything
          */
         $this->_checkAcl('destroy');
         $this->_model->delete($where);
     } catch (Garp_Auth_Exception $e) {
         /**
          * If that fails, check if the user is allowed to update her own material
          * AND if the current item is hers.
          */
         $this->_checkAcl('destroy_own');
         /**
          * Good, the user is allowed to 'destroy_own'. In that case we have to check
          * if the current item is actually the user's.
          */
         $rows = $this->_model->fetchAll($where);
         foreach ($rows as $row) {
             if (!$this->_itemBelongsToUser($row->toArray())) {
                 throw new Garp_Auth_Exception('You are only allowed to delete your own material.');
             }
             $row->delete();
         }
     }
 }
Example #2
0
 /**
  * Rollback all inserts when the import throws an error halfway
  * @param Garp_Model $model
  * @param Array $primaryKeys Collection of primary keys
  * @return Void
  */
 public function rollback(Garp_Model $model, array $primaryKeys)
 {
     if (empty($primaryKeys)) {
         return;
     }
     $primaryCols = (array) $model->info(Zend_Db_Table::PRIMARY);
     $where = array();
     foreach ($primaryKeys as $pk) {
         $recordWhere = array();
         foreach ((array) $pk as $i => $key) {
             $recordWhere[] = $model->getAdapter()->quoteIdentifier(current($primaryCols)) . ' = ' . $model->getAdapter()->quote($key);
         }
         $recordWhere = implode(' AND ', $recordWhere);
         $recordWhere = '(' . $recordWhere . ')';
         $where[] = $recordWhere;
         reset($primaryCols);
     }
     $where = implode(' OR ', $where);
     if (empty($where)) {
         return;
     }
     $model->delete($where);
 }