Rollback to a previous version of an entity.

@param string $entity
@param int    $id

@return Redirect
194807
public function rollback($entity, $id)
    {
        $modelString = str_replace('_', '\\', $entity);

        if (!class_exists($modelString)) {
            Cms::notification('Could not rollback Model not found', 'warning');

            return redirect(URL::previous());
        }

        $model = app($modelString);
        $modelInstance = $model->find($id);

        $archive = Archive::where('entity_id', $id)->where('entity_type', $modelString)->limit(1)->offset(1)->orderBy('id', 'desc')->first();

        if (!$archive) {
            Cms::notification('Could not rollback', 'warning');

            return redirect(URL::previous());
        }

        $archiveData = (array) json_decode($archive->entity_data);

        $modelInstance->fill($archiveData);
        $modelInstance->save();

        Cms::notification('Rollback was successful', 'success');

        return redirect(URL::previous());
    }
861093
public function update(Update $request, $id)
    {
        try {
            $permission = $this->repository->findById($id);

            $data = $request->all();

            $permission->update($data);

            return $this->redirect('permissions.index');
        } catch (ModelNotFoundException $e) {
            return $this->redirectNotFound();
        }
    }
1071163
public function deleteAction(Request $request, $id)
    {
        $this->checkIfUserHasPermission(Permission::CREATE_DELETE);

        $this->getParentEntityDefinition($request);

        $entity = $this->getEntity($id);

        $this->getEventDispatcher()->dispatch(
            Events::PRE_CRUD_CONTROLLER_ACTION,
            new CrudControllerActionEvent($this->meta, __FUNCTION__)
        );

        $form = $this->getAdminFormFactory()->createDeleteForm($entity, $this->entityClass)->handleRequest($request);

        if ($this->getFormHandler()->handleDeleteForm($form, $entity)) {
            $this->getEventDispatcher()->dispatch(CrudEvents::DELETED, new DeletedEvent($this->getUser(), $entity));

            return $this->redirect($this->getAdminRouter()->generate($entity, $this->entityClass, AdminRouter::TYPE_INDEX));
        }

        $url = $request->headers->get(
            'referer',
            $this->getAdminRouter()->generate($entity, $this->entityClass, AdminRouter::TYPE_INDEX)
        );

        return $this->redirect($url);
    }
1172749
public function rollback($e) {
        if ($this->is_disposed()) {
            throw new dml_transaction_exception('Transactions already disposed', $this);
        }
        $this->database->rollback_delegated_transaction($this, $e);
    }
117730
public function checkAction(Request $request, $id, $repository)
    {
        $entityIsLocked = false;
        $message = '';

        /** @var LockableEntityInterface $entity */
        $entity = $this->getEntityManager()->getRepository($repository)->find($id);

        try {
            /** @var EntityVersionLockService $entityVersionLockservice */
            $entityVersionLockService = $this->get('kunstmaan_entity.admin_entity.entity_version_lock_service');

            $entityIsLocked = $entityVersionLockService->isEntityLocked($this->getUser(), $entity);

            if ($entityIsLocked) {
                $user = $entityVersionLockService->getUsersWithEntityVersionLock($entity, $this->getUser());
                $message = $this->get('translator')->trans('kuma_admin_list.edit.flash.locked', array('%user%' => implode(', ', $user)));
            }
        } catch (AccessDeniedException $ade) {
        }

        return new JsonResponse(['lock' => $entityIsLocked, 'message' => $message]);
    }
1103525
public function deleteAction(Request $request, $id)
        {

            /** @var Customer $oCustomer */
            $oCustomer = CustomerQuery::create()->findOneById($id);

            if ($oCustomer === null) {
                throw $this->createNotFoundException('Unable to find Customer entity.');

            }
            $oCustomer->delete();

            return $this->redirect($this->generateUrl('backend_system_customer'));
        }
891851
public function refresh ($entity)
    {
        // Return if not saved and not in database.
        if (! $entity->_saved) return false;
        $structure = $this->getEntityStructure($entity);

        // ID Data.
        $idColumn = $structure->primaryColumn->name;
        $idValue = $entity->_id;

        if ($structure->primaryColumn->type === 'integer')
            $idValue = intval($idValue);

        // Clear Relationship Cache.
        $entity::clearCache();

        // Query for refreshing.
        $query = new Query($entity);
        $newEntity = $query->select()
            ->where($idColumn, $idValue)
            ->one();

        // If no entity is found (when refreshing).
        if (! $newEntity) return false;

        // Map to the old instance
        foreach ($structure->columns as $column) {
            $entity->{$column->propertyName} = $newEntity->{$column->propertyName};
        }

        return true;
    }
1281016
public function delete($id)
    {
        $this->validateId($id);

        $entity = $this->getMapper()->find($id);

        if (null === $entity) {
            throw new \InvalidArgumentException('No entity found for id "' . $id . '"');
        }

        $this->getMapper()->remove($entity);

        return $this;
    }
696407
public function update($id, Request $request)
    {
        $entity = $this->getEntityById($id);

        if (!$entity) {
            return $this->response(null, Response::HTTP_NOT_FOUND);
        }

        $params = $request->only($this->fillable);

        $result = $this->manager->update($entity, $params);

        if (!$result->ok()) {
            return $this->response(['errors' => $result->getSimpleErrors()], Response::HTTP_BAD_REQUEST);
        }

        return $this->response($this->serialize($result->getResource(), $request), Response::HTTP_OK);
    }
1079418
public function deleteAction(Request $request, $id)
    {
        $entity = $this->getRepository()->find($id);

        if (!$entity) {
            throw $this->createNotFoundException('Unable to find ' . $this->getEntityName() . '.');
        }

        $em = $this->getDoctrine()->getManager();

        $this->get('session')->getFlashBag()->add('success', ucfirst($this->getEntityName()) . ' has been deleted!');

        $em->remove($entity);
        $em->flush();

        if ($request->getMethod() == "DELETE") {
            return new JsonResponse([
                'success' => true
            ]);
        } else {
            return $this->redirect($this->getRefererUrl());
        }
    }
1310395
private function down($id)
    {
        /* @var Gallery_Entity_Table_Image $table */
        $table = ORM::getTable($this, 'Image');
        /* @var Gallery_Entity_Image $image */
        $image = $table->find($id);
        $table->moveDown($image);
        HTTP::goback();
    }
314024
protected function handleLastId($entity, $id)
    {
        $entity = $this->getUserInputEntity($entity);
        $this->lastId = $id;
        $entity = $this->makeSQLUnsafe($entity);
        $this->saveLastId($entity, $this->lastId);
        $this->setKeyword($entity . '_id', $this->lastId);
    }
113291
public function update(Update $request, $id)
    {
        try {
            $data = !$request->has('password') ? $request->except('password') : $this->inputAll();

            $user = $this->repository->findById($id);

            $user->update($data);

            $user->roles()->sync((array) \Input::get('role'));

            return $this->redirect('users.index');
        } catch (ModelNotFoundException $e) {
            return $this->redirectNotFound();
        }
    }
535800
public function call_previous(\Asgard\Entity\Entity $entity) {
		$orm = $entity::where(['position < ?' => $entity->position])->orderBy('position DESC');
		if($this->category)
			$orm->where($this->category, $entity->get($this->category));

		return $orm->first();
	}
856409
public function delete(Entity $entity) {
    $this->remove($entity);
    $this->_em->flush();
    
    return $this;
  }
957824
public function revert(&$entity, $revision)
    {
        /** @var ClassMetadataInfo $meta */
        $meta = $this->getClassMetadata(get_class($entity));

        $data = $this->getRevisionData($entity, ['revision_id = :revisionId'], ['revisionId' => $revision], 1);

        /** @var \ReflectionProperty[] $revisedProperties */
        $revisedProperties = $this->annotationReader->getRevisedProperties($entity);

        $exception = null;
        foreach ($revisedProperties as $field => $property) {
            if (! key_exists($field, $revisedProperties)) {
                continue;
            }

            if (isset($meta->fieldMappings[$field])) {
                $columnName = $meta->fieldMappings[$field]['columnName'];
            } elseif (isset($meta->associationMappings[$field])) {
                $columnName = $meta->associationMappings[$field]['joinColumns'][0]['name'];
            } else {
                throw new \Exception('Cannot find column name for' . $field);
            }

            $value = $data[$columnName];

            $property = $meta->getReflectionProperty($field);
            $property->setValue($entity, $value);

            if ($field == 'deletedAt' && $value !== null) {
                $exception = new DeletedException('Entity is deleted in this revision');
            }
        }

        if ($exception) {
            $exception->setEntity($entity);
            throw $exception;
        }

        return $entity;
    }
796729
public function deleteObject($entity, $_id)
	{
		$retValue = true;
		$arrayWhere = array('_id' => $_id);

		if (! is_null($this->_conn)){
			$this->_conn->delete($entity, $arrayWhere);

			if ($this->error($this->_conn->error()))
				$retValue = false;
		}
		
		return $retValue;
	}