Ejemplo n.º 1
0
 public function update($data, $where)
 {
     try {
         $status = parent::update($data, $where);
     } catch (Exception $e) {
         if (23000 == $e->getCode()) {
             $this->getLogger()->info('Duplicate ISBN found:' . $where);
             $this->getLogger()->notice('Dependent books are updated to new ISBN and current ISBN deleted');
             try {
                 $newData = array_intersect_key($data, array('isbn_id' => 0));
                 $status = $this->getAdapter()->update('book', $newData, $where);
                 $this->delete($where);
                 return $status;
             } catch (Exception $e) {
                 throw $e;
             }
         }
         throw $e;
     }
     return $status;
 }
Ejemplo n.º 2
0
 /**
  * (C)reate, (R)ead, (U)pdate, (D)elete function.
  * 
  * All CRUD activities pass through this method.
  * @return mixed Status of Add/Update/Delete commands if successful else exception string with header status {@link $errorCode}.
  */
 public function crudAction()
 {
     $request = $this->getRequest();
     $status = NULL;
     $errorCode = 400;
     if ($request->isXmlHttpRequest() and $request->isPost()) {
         self::createDbCols();
         switch ($request->getParam('oper')) {
             case 'add':
                 $rdata = $request->getParams();
                 $data = self::paramData($rdata);
                 try {
                     $status = $this->model->insert($data);
                     echo $status;
                 } catch (Zend_Exception $e) {
                     $this->_helper->logger->err($e->getMessage());
                     $this->_helper->logger->alert('Row insertion failure :');
                     $this->_helper->logger('Status = ' . $status);
                     $this->_helper->logger->alert('Request Data :');
                     $this->_helper->logger($rdata);
                     $this->_helper->logger->alert('Processed data :');
                     $this->_helper->logger($data);
                     throw $e;
                 }
                 if ($status) {
                     $this->_helper->logger->debug('Status :');
                     $this->_helper->logger($status);
                 }
                 return true;
                 break;
             case 'del':
                 $id = $request->getParam('id');
                 $where = self::whereData($id);
                 try {
                     $status = $this->model->delete($where);
                 } catch (Zend_Exception $e) {
                     $this->_helper->logger->err($e->getMessage());
                     $this->_helper->logger->err('Row deletion failure :');
                     $this->_helper->logger('Status = ' . $status);
                     $this->_helper->logger->alert('WHERE clause :');
                     $this->_helper->logger($where);
                     $this->getResponse()->setHttpResponseCode($errorCode);
                     throw $e;
                 }
                 if ($status) {
                     $this->_helper->logger->debug('Status :');
                     $this->_helper->logger($status);
                 }
                 return true;
                 break;
             case 'edit':
                 $rdata = $request->getParams();
                 $data = self::paramData($rdata);
                 $id = $rdata['id'];
                 $where = self::whereData($id);
                 try {
                     $status = $this->model->update($data, $where);
                 } catch (Zend_Exception $e) {
                     $this->_helper->logger->err($e->getMessage());
                     $this->_helper->logger->err('Row updation failure :');
                     $this->_helper->logger('Status = ' . $status);
                     $this->getResponse()->setHttpResponseCode($errorCode);
                     throw $e;
                 }
                 if ($status) {
                     $this->_helper->logger->debug('Status :');
                     $this->_helper->logger($status);
                 }
                 return true;
                 break;
             default:
                 $this->_helper->logger->crit('The param "oper" has unexpected value :' . $request->getParam('oper'));
                 return false;
         }
     } else {
         $this->_helper->logger->err('Criteria to access CRUD is not fullfilled');
         header("HTTP/1.1 403 Forbidden");
         die;
     }
 }