mirror of
https://github.com/wallabag/wallabag.git
synced 2025-01-22 22:58:08 +00:00
remove isDeleted flag
This commit is contained in:
parent
aa4d6562c1
commit
1d14779154
6 changed files with 23 additions and 62 deletions
|
@ -192,8 +192,9 @@ class EntryController extends Controller
|
|||
{
|
||||
$this->checkUserAction($entry);
|
||||
|
||||
$entry->setDeleted(1);
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->remove($entry);
|
||||
$em->flush();
|
||||
|
||||
$this->get('session')->getFlashBag()->add(
|
||||
'notice',
|
||||
|
|
|
@ -43,7 +43,6 @@ class WallabagRestController extends Controller
|
|||
* parameters={
|
||||
* {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by archived status."},
|
||||
* {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false, all entries by default", "description"="filter by starred status."},
|
||||
* {"name"="delete", "dataType"="boolean", "required"=false, "format"="true or false, default '0'", "description"="filter by deleted status."},
|
||||
* {"name"="sort", "dataType"="string", "required"=false, "format"="'created' or 'updated', default 'created'", "description"="sort entries by date."},
|
||||
* {"name"="order", "dataType"="string", "required"=false, "format"="'asc' or 'desc', default 'desc'", "description"="order of sort."},
|
||||
* {"name"="page", "dataType"="integer", "required"=false, "format"="default '1'", "description"="what page you want."},
|
||||
|
@ -57,7 +56,6 @@ class WallabagRestController extends Controller
|
|||
{
|
||||
$isArchived = $request->query->get('archive');
|
||||
$isStarred = $request->query->get('star');
|
||||
$isDeleted = $request->query->get('delete', 0);
|
||||
$sort = $request->query->get('sort', 'created');
|
||||
$order = $request->query->get('order', 'desc');
|
||||
$page = $request->query->get('page', 1);
|
||||
|
@ -67,7 +65,7 @@ class WallabagRestController extends Controller
|
|||
$entries = $this
|
||||
->getDoctrine()
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $isDeleted, $sort, $order);
|
||||
->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order);
|
||||
|
||||
if (!($entries)) {
|
||||
throw $this->createNotFoundException();
|
||||
|
@ -138,8 +136,7 @@ class WallabagRestController extends Controller
|
|||
* {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."},
|
||||
* {"name"="archive", "dataType"="boolean", "required"=false, "format"="true or false", "description"="archived the entry."},
|
||||
* {"name"="star", "dataType"="boolean", "required"=false, "format"="true or false", "description"="starred the entry."},
|
||||
* {"name"="delete", "dataType"="boolean", "required"=false, "format"="true or false", "description"="flag as deleted. Default false. In case that you don't want to *really* remove it.."},
|
||||
* }
|
||||
* }
|
||||
* )
|
||||
* @return Entry
|
||||
*/
|
||||
|
@ -148,7 +145,6 @@ class WallabagRestController extends Controller
|
|||
$title = $request->request->get("title");
|
||||
$tags = $request->request->get("tags", array());
|
||||
$isArchived = $request->request->get("archive");
|
||||
$isDeleted = $request->request->get("delete");
|
||||
$isStarred = $request->request->get("star");
|
||||
|
||||
if (!is_null($title)) {
|
||||
|
@ -159,10 +155,6 @@ class WallabagRestController extends Controller
|
|||
$entry->setArchived($isArchived);
|
||||
}
|
||||
|
||||
if (!is_null($isDeleted)) {
|
||||
$entry->setDeleted($isDeleted);
|
||||
}
|
||||
|
||||
if (!is_null($isStarred)) {
|
||||
$entry->setStarred($isStarred);
|
||||
}
|
||||
|
@ -185,15 +177,13 @@ class WallabagRestController extends Controller
|
|||
*/
|
||||
public function deleteEntriesAction(Entry $entry)
|
||||
{
|
||||
if ($entry->isDeleted()) {
|
||||
throw new NotFoundHttpException('This entry is already deleted');
|
||||
}
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$entry->setDeleted(1);
|
||||
$em->remove($entry);
|
||||
$em->flush();
|
||||
|
||||
return $entry;
|
||||
$json = $this->get('serializer')->serialize($entry, 'json');
|
||||
|
||||
return new Response($json, 200, array('application/json'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -57,13 +57,6 @@ class Entry
|
|||
*/
|
||||
private $isStarred = false;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*
|
||||
* @ORM\Column(name="is_deleted", type="boolean")
|
||||
*/
|
||||
private $isDeleted = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
|
@ -280,22 +273,6 @@ class Entry
|
|||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function isDeleted()
|
||||
{
|
||||
return $this->isDeleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $isDeleted
|
||||
*/
|
||||
public function setDeleted($isDeleted)
|
||||
{
|
||||
$this->isDeleted = $isDeleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -24,7 +24,6 @@ class EntryRepository extends EntityRepository
|
|||
->leftJoin('e.user', 'u')
|
||||
->where('e.isArchived = false')
|
||||
->andWhere('u.id =:userId')->setParameter('userId', $userId)
|
||||
->andWhere('e.isDeleted=false')
|
||||
->orderBy('e.createdAt', 'desc')
|
||||
->getQuery();
|
||||
|
||||
|
@ -51,7 +50,6 @@ class EntryRepository extends EntityRepository
|
|||
->leftJoin('e.user', 'u')
|
||||
->where('e.isArchived = true')
|
||||
->andWhere('u.id =:userId')->setParameter('userId', $userId)
|
||||
->andWhere('e.isDeleted=false')
|
||||
->orderBy('e.createdAt', 'desc')
|
||||
->getQuery();
|
||||
|
||||
|
@ -78,7 +76,6 @@ class EntryRepository extends EntityRepository
|
|||
->leftJoin('e.user', 'u')
|
||||
->where('e.isStarred = true')
|
||||
->andWhere('u.id =:userId')->setParameter('userId', $userId)
|
||||
->andWhere('e.isDeleted = false')
|
||||
->orderBy('e.createdAt', 'desc')
|
||||
->getQuery();
|
||||
|
||||
|
@ -93,13 +90,12 @@ class EntryRepository extends EntityRepository
|
|||
* @param int $userId
|
||||
* @param bool $isArchived
|
||||
* @param bool $isStarred
|
||||
* @param bool $isDeleted
|
||||
* @param string $sort
|
||||
* @param string $order
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function findEntries($userId, $isArchived = null, $isStarred = null, $isDeleted = null, $sort = 'created', $order = 'ASC')
|
||||
public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC')
|
||||
{
|
||||
$qb = $this->createQueryBuilder('e')
|
||||
->where('e.user =:userId')->setParameter('userId', $userId);
|
||||
|
@ -112,10 +108,6 @@ class EntryRepository extends EntityRepository
|
|||
$qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
|
||||
}
|
||||
|
||||
if (null !== $isDeleted) {
|
||||
$qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', (bool) $isDeleted);
|
||||
}
|
||||
|
||||
if ('created' === $sort) {
|
||||
$qb->orderBy('e.createdAt', $order);
|
||||
} elseif ('updated' === $sort) {
|
||||
|
|
|
@ -161,18 +161,15 @@ class EntryControllerTest extends WallabagTestCase
|
|||
$content = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findOneByIsDeleted(false);
|
||||
->findOneById(1);
|
||||
|
||||
$client->request('GET', '/delete/'.$content->getId());
|
||||
|
||||
$this->assertEquals(302, $client->getResponse()->getStatusCode());
|
||||
|
||||
$res = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findOneById($content->getId());
|
||||
$client->request('GET', '/delete/'.$content->getId());
|
||||
|
||||
$this->assertEquals($res->isDeleted(), true);
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
public function testViewOtherUserEntry()
|
||||
|
|
|
@ -130,7 +130,7 @@ class WallabagRestControllerTest extends WallabagTestCase
|
|||
$entry = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findOneByIsDeleted(false);
|
||||
->findOneByUser(1);
|
||||
|
||||
if (!$entry) {
|
||||
$this->markTestSkipped('No content found in db.');
|
||||
|
@ -140,10 +140,14 @@ class WallabagRestControllerTest extends WallabagTestCase
|
|||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
|
||||
$res = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findOneById($entry->getId());
|
||||
$this->assertEquals($res->isDeleted(), true);
|
||||
// We'll try to delete this entry again
|
||||
$client->request('GET', '/api/salts/admin.json');
|
||||
$salt = json_decode($client->getResponse()->getContent());
|
||||
|
||||
$headers = $this->generateHeaders('admin', 'test', $salt[0]);
|
||||
|
||||
$client->request('DELETE', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue