Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4026 from wallabag/3760-ignorelist-db
Move Ignore Origin rules to database
- Loading branch information
Showing
54 changed files
with
2,384 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Application\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Wallabag\CoreBundle\Doctrine\WallabagMigration; | ||
|
||
/** | ||
* Add tables for the ignore origin rules. | ||
*/ | ||
final class Version20190826204730 extends WallabagMigration | ||
{ | ||
public function up(Schema $schema): void | ||
{ | ||
if (false === $schema->hasTable($this->getTable('ignore_origin_user_rule'))) { | ||
$userTable = $schema->createTable($this->getTable('ignore_origin_user_rule', true)); | ||
$userTable->addColumn('id', 'integer', ['autoincrement' => true]); | ||
$userTable->addColumn('config_id', 'integer'); | ||
$userTable->addColumn('rule', 'string', ['length' => 255]); | ||
$userTable->addIndex(['config_id'], 'idx_config'); | ||
$userTable->setPrimaryKey(['id']); | ||
$userTable->addForeignKeyConstraint($this->getTable('config'), ['config_id'], ['id'], [], 'fk_config'); | ||
|
||
if ('postgresql' === $this->connection->getDatabasePlatform()->getName()) { | ||
$schema->dropSequence('ignore_origin_user_rule_id_seq'); | ||
$schema->createSequence('ignore_origin_user_rule_id_seq'); | ||
} | ||
} | ||
|
||
if (false === $schema->hasTable($this->getTable('ignore_origin_instance_rule'))) { | ||
$instanceTable = $schema->createTable($this->getTable('ignore_origin_instance_rule', true)); | ||
$instanceTable->addColumn('id', 'integer', ['autoincrement' => true]); | ||
$instanceTable->addColumn('rule', 'string', ['length' => 255]); | ||
$instanceTable->setPrimaryKey(['id']); | ||
|
||
if ('postgresql' === $this->connection->getDatabasePlatform()->getName()) { | ||
$schema->dropSequence('ignore_origin_instance_rule_id_seq'); | ||
$schema->createSequence('ignore_origin_instance_rule_id_seq'); | ||
} | ||
} | ||
} | ||
|
||
public function postUp(Schema $schema): void | ||
{ | ||
foreach ($this->container->getParameter('wallabag_core.default_ignore_origin_instance_rules') as $entity) { | ||
$previous_rule = $this->container | ||
->get('doctrine.orm.default_entity_manager') | ||
->getConnection() | ||
->fetchArray('SELECT * FROM ' . $this->getTable('ignore_origin_instance_rule') . " WHERE rule = '" . $entity['rule'] . "'"); | ||
|
||
if (false === $previous_rule) { | ||
$this->addSql('INSERT INTO ' . $this->getTable('ignore_origin_instance_rule') . " (rule) VALUES ('" . $entity['rule'] . "');"); | ||
} | ||
} | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$schema->dropTable($this->getTable('ignore_origin_user_rule')); | ||
$schema->dropTable($this->getTable('ignore_origin_instance_rule')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
src/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
|
||
namespace Wallabag\CoreBundle\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use Wallabag\CoreBundle\Entity\IgnoreOriginInstanceRule; | ||
|
||
/** | ||
* IgnoreOriginInstanceRuleController controller. | ||
* | ||
* @Route("/ignore-origin-instance-rules") | ||
*/ | ||
class IgnoreOriginInstanceRuleController extends Controller | ||
{ | ||
/** | ||
* Lists all IgnoreOriginInstanceRule entities. | ||
* | ||
* @Route("/", name="ignore_origin_instance_rules_index", methods={"GET"}) | ||
*/ | ||
public function indexAction() | ||
{ | ||
$rules = $this->get('wallabag_core.ignore_origin_instance_rule_repository')->findAll(); | ||
|
||
return $this->render('WallabagCoreBundle:IgnoreOriginInstanceRule:index.html.twig', [ | ||
'rules' => $rules, | ||
]); | ||
} | ||
|
||
/** | ||
* Creates a new ignore origin instance rule entity. | ||
* | ||
* @Route("/new", name="ignore_origin_instance_rules_new", methods={"GET", "POST"}) | ||
* | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
*/ | ||
public function newAction(Request $request) | ||
{ | ||
$ignoreOriginInstanceRule = new IgnoreOriginInstanceRule(); | ||
|
||
$form = $this->createForm('Wallabag\CoreBundle\Form\Type\IgnoreOriginInstanceRuleType', $ignoreOriginInstanceRule); | ||
$form->handleRequest($request); | ||
|
||
if ($form->isSubmitted() && $form->isValid()) { | ||
$em = $this->getDoctrine()->getManager(); | ||
$em->persist($ignoreOriginInstanceRule); | ||
$em->flush(); | ||
|
||
$this->get('session')->getFlashBag()->add( | ||
'notice', | ||
$this->get('translator')->trans('flashes.ignore_origin_instance_rule.notice.added') | ||
); | ||
|
||
return $this->redirectToRoute('ignore_origin_instance_rules_index'); | ||
} | ||
|
||
return $this->render('WallabagCoreBundle:IgnoreOriginInstanceRule:new.html.twig', [ | ||
'rule' => $ignoreOriginInstanceRule, | ||
'form' => $form->createView(), | ||
]); | ||
} | ||
|
||
/** | ||
* Displays a form to edit an existing ignore origin instance rule entity. | ||
* | ||
* @Route("/{id}/edit", name="ignore_origin_instance_rules_edit", methods={"GET", "POST"}) | ||
* | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
*/ | ||
public function editAction(Request $request, IgnoreOriginInstanceRule $ignoreOriginInstanceRule) | ||
{ | ||
$deleteForm = $this->createDeleteForm($ignoreOriginInstanceRule); | ||
$editForm = $this->createForm('Wallabag\CoreBundle\Form\Type\IgnoreOriginInstanceRuleType', $ignoreOriginInstanceRule); | ||
$editForm->handleRequest($request); | ||
|
||
if ($editForm->isSubmitted() && $editForm->isValid()) { | ||
$em = $this->getDoctrine()->getManager(); | ||
$em->persist($ignoreOriginInstanceRule); | ||
$em->flush(); | ||
|
||
$this->get('session')->getFlashBag()->add( | ||
'notice', | ||
$this->get('translator')->trans('flashes.ignore_origin_instance_rule.notice.updated') | ||
); | ||
|
||
return $this->redirectToRoute('ignore_origin_instance_rules_index'); | ||
} | ||
|
||
return $this->render('WallabagCoreBundle:IgnoreOriginInstanceRule:edit.html.twig', [ | ||
'rule' => $ignoreOriginInstanceRule, | ||
'edit_form' => $editForm->createView(), | ||
'delete_form' => $deleteForm->createView(), | ||
]); | ||
} | ||
|
||
/** | ||
* Deletes a site credential entity. | ||
* | ||
* @Route("/{id}", name="ignore_origin_instance_rules_delete", methods={"DELETE"}) | ||
* | ||
* @return \Symfony\Component\HttpFoundation\RedirectResponse | ||
*/ | ||
public function deleteAction(Request $request, IgnoreOriginInstanceRule $ignoreOriginInstanceRule) | ||
{ | ||
$form = $this->createDeleteForm($ignoreOriginInstanceRule); | ||
$form->handleRequest($request); | ||
|
||
if ($form->isSubmitted() && $form->isValid()) { | ||
$this->get('session')->getFlashBag()->add( | ||
'notice', | ||
$this->get('translator')->trans('flashes.ignore_origin_instance_rule.notice.deleted') | ||
); | ||
|
||
$em = $this->getDoctrine()->getManager(); | ||
$em->remove($ignoreOriginInstanceRule); | ||
$em->flush(); | ||
} | ||
|
||
return $this->redirectToRoute('ignore_origin_instance_rules_index'); | ||
} | ||
|
||
/** | ||
* Creates a form to delete a ignore origin instance rule entity. | ||
* | ||
* @param IgnoreOriginInstanceRule $ignoreOriginInstanceRule The ignore origin instance rule entity | ||
* | ||
* @return \Symfony\Component\Form\Form The form | ||
*/ | ||
private function createDeleteForm(IgnoreOriginInstanceRule $ignoreOriginInstanceRule) | ||
{ | ||
return $this->createFormBuilder() | ||
->setAction($this->generateUrl('ignore_origin_instance_rules_delete', ['id' => $ignoreOriginInstanceRule->getId()])) | ||
->setMethod('DELETE') | ||
->getForm() | ||
; | ||
} | ||
} |
Oops, something went wrong.