/** * Deletes a archivo * */ public function deleteAction() { if (!$this->request->isPost()) { return $this->dispatcher->forward(array("controller" => "archivo", "action" => "index")); } $id = $this->request->getPost('id'); $archivo = Archivo::findFirstByarchivo_id($id); if (!$archivo) { $this->flash->error("El archivo no fue encontrado"); return $this->dispatcher->forward(array("controller" => "archivo", "action" => "index")); } try { $this->db->begin(); $path = $archivo->archivo_carpeta . '/' . $archivo->archivo_nombre; if (!$archivo->delete()) { foreach ($archivo->getMessages() as $message) { $this->flash->error($message); } return $this->dispatcher->forward(array("controller" => "archivo", "action" => "search")); } else { //el archivo fue eliminado de la bd, asi que procedemos a eliminarlo del servidor. if (file_exists($path)) { unlink($path); //Compruebo que se borro if (file_exists($path)) { $this->db->rollback(); $this->flash->error("Hubo un problema al eliminar el archivo, pruebe nuevamente"); } else { $this->db->commit(); $this->flash->success("El archivo ha sido eliminado correctamente"); } } } } catch (Phalcon\Mvc\Model\Transaction\Failed $e) { $this->flash->error('Transaccion Fallida: ', $e->getMessage()); } catch (\Exception $e) { $this->flash->error('Transaccion Fallida2: ', $e->getMessage()); } return $this->dispatcher->forward(array("controller" => "archivo", "action" => "index")); }