Added a migration to set the slugs.
This commit is contained in:
parent
480e0e5568
commit
1613b75fe8
1 changed files with 73 additions and 0 deletions
73
app/DoctrineMigrations/Version20140710120656.php
Executable file
73
app/DoctrineMigrations/Version20140710120656.php
Executable file
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace Application\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Hackspace\Bundle\CalciferBundle\Entity\Event;
|
||||
use Hackspace\Bundle\CalciferBundle\Entity\Location;
|
||||
use Hackspace\Bundle\CalciferBundle\Entity\Tag;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
class Version20140710120656 extends AbstractMigration implements ContainerAwareInterface
|
||||
{
|
||||
/** @var ContainerInterface */
|
||||
private $container;
|
||||
|
||||
public function setContainer(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
/** @var EntityManager $em */
|
||||
$em = $this->container->get('doctrine.orm.entity_manager');
|
||||
$repo = $em->getRepository('CalciferBundle:Event');
|
||||
$entities = $repo->findAll();
|
||||
if (count($entities) > 0) {
|
||||
foreach($entities as $entity) {
|
||||
/** @var Event $entity */
|
||||
$entity->setSlug(\URLify::filter($entity->getSummary(),255,'de'));
|
||||
$em->persist($entity);
|
||||
$em->flush();
|
||||
}
|
||||
}
|
||||
|
||||
$repo = $em->getRepository('CalciferBundle:Location');
|
||||
$entities = $repo->findAll();
|
||||
if (count($entities) > 0) {
|
||||
foreach($entities as $entity) {
|
||||
/** @var Location $entity */
|
||||
$entity->setSlug(\URLify::filter($entity->getName(),255,'de'));
|
||||
$em->persist($entity);
|
||||
$em->flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$repo = $em->getRepository('CalciferBundle:Tag');
|
||||
$entities = $repo->findAll();
|
||||
if (count($entities) > 0) {
|
||||
foreach($entities as $entity) {
|
||||
/** @var Tag $entity */
|
||||
$entity->setSlug(\URLify::filter($entity->getName(),255,'de'));
|
||||
$em->persist($entity);
|
||||
$em->flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function down(Schema $schema)
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
|
||||
}
|
||||
}
|
Reference in a new issue