From 04660e191d7f633014e7c55036fe4e1d06e7e675 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Mon, 2 Mar 2015 20:39:45 +0300 Subject: [PATCH 1/6] Entities generated from the old database. --- .../Bundle/CopyPasteBundle/Entity/Lang.php | 141 ++++++++ .../Bundle/CopyPasteBundle/Entity/Paste.php | 320 ++++++++++++++++++ 2 files changed, 461 insertions(+) create mode 100644 src/Skobkin/Bundle/CopyPasteBundle/Entity/Lang.php create mode 100644 src/Skobkin/Bundle/CopyPasteBundle/Entity/Paste.php diff --git a/src/Skobkin/Bundle/CopyPasteBundle/Entity/Lang.php b/src/Skobkin/Bundle/CopyPasteBundle/Entity/Lang.php new file mode 100644 index 0000000..38af62b --- /dev/null +++ b/src/Skobkin/Bundle/CopyPasteBundle/Entity/Lang.php @@ -0,0 +1,141 @@ +id; + } + + /** + * Set name + * + * @param string $name + * @return Lang + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set code + * + * @param string $file + * @return Lang + */ + public function setCode($code) + { + $this->code = $code; + + return $this; + } + + /** + * Get code + * + * @return string + */ + public function getCode() + { + return $this->code; + } + + /** + * Set enabled + * + * @param boolean $enabled + * @return Lang + */ + public function setEnabled($enabled) + { + $this->enabled = $enabled; + + return $this; + } + + /** + * Get enabled + * + * @return boolean + */ + public function getEnabled() + { + return $this->enabled; + } + + /** + * Check if language is enabled + * + * @return boolean + */ + public function isEnabled() + { + return $this->enabled; + } +} diff --git a/src/Skobkin/Bundle/CopyPasteBundle/Entity/Paste.php b/src/Skobkin/Bundle/CopyPasteBundle/Entity/Paste.php new file mode 100644 index 0000000..d8d5035 --- /dev/null +++ b/src/Skobkin/Bundle/CopyPasteBundle/Entity/Paste.php @@ -0,0 +1,320 @@ +id; + } + + /** + * Set text + * + * @param string $text + * @return Paste + */ + public function setText($text) + { + $this->text = $text; + + return $this; + } + + /** + * Get text + * + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * Set description + * + * @param string $description + * @return Paste + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + /** + * Get codeComment + * + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Set language + * + * @param integer $language + * @return Paste + */ + public function setLanguage($language) + { + $this->language = $language; + + return $this; + } + + /** + * Get language + * + * @return integer + */ + public function getLanguage() + { + return $this->language; + } + + /** + * Set filename + * + * @param string $filename + * @return Paste + */ + public function setFilename($filename) + { + $this->fileName = $filename; + + return $this; + } + + /** + * Get filename + * + * @return string + */ + public function getFilename() + { + return $this->fileName; + } + + /** + * Set author + * + * @param string $author + * @return Paste + */ + public function setAuthor($author) + { + $this->author = $author; + + return $this; + } + + /** + * Get author + * + * @return string + */ + public function getAuthor() + { + return $this->author; + } + + /** + * Set publication date + * + * @param \DateTime $datePublished + * @return Paste + */ + public function setDatePublished($datePublished) + { + $this->datePublished = $datePublished; + + return $this; + } + + /** + * Get publication date + * + * @return \DateTime + */ + public function getDatePublished() + { + return $this->datePublished; + } + + /** + * Set dateExp + * + * @param \DateTime $dateExpire + * @return Paste + */ + public function setDateExpire($dateExpire) + { + $this->dateExpire = $dateExpire; + + return $this; + } + + /** + * Get dateExp + * + * @return \DateTime + */ + public function getDateExpire() + { + return $this->dateExpire; + } + + /** + * Set ip + * + * @param string $ip + * @return Paste + */ + public function setIp($ip) + { + $this->ip = $ip; + + return $this; + } + + /** + * Get ip + * + * @return string + */ + public function getIp() + { + return $this->ip; + } + + /** + * Set secret + * + * @param string $secret + * @return Paste + */ + public function setSecret($secret) + { + $this->secret = $secret; + + return $this; + } + + /** + * Get secret + * + * @return string + */ + public function getSecret() + { + return $this->secret; + } + + /** + * Check if copypaste is private + * + * @return boolean + */ + public function isPrivate() + { + return ($this->secret === null) ? false : true; + } +} From 442e29adc60db8c12ba5dcd5673ba938e6d14b56 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Mon, 2 Mar 2015 21:10:10 +0300 Subject: [PATCH 2/6] First migration. Creates database in copypaste1 format. --- app/AppKernel.php | 1 + .../Version20150302205121.php | 60 +++++++++ app/config/config.yml | 6 + composer.json | 4 +- composer.lock | 123 +++++++++++++++++- 5 files changed, 191 insertions(+), 3 deletions(-) create mode 100644 app/DoctrineMigrations/Version20150302205121.php diff --git a/app/AppKernel.php b/app/AppKernel.php index faee254..a75d4a0 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -15,6 +15,7 @@ class AppKernel extends Kernel new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), new Symfony\Bundle\AsseticBundle\AsseticBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), + new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), new Skobkin\Bundle\CopyPasteBundle\SkobkinCopyPasteBundle(), ); diff --git a/app/DoctrineMigrations/Version20150302205121.php b/app/DoctrineMigrations/Version20150302205121.php new file mode 100644 index 0000000..7f4d312 --- /dev/null +++ b/app/DoctrineMigrations/Version20150302205121.php @@ -0,0 +1,60 @@ +abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $schemaManager = $this->connection->getSchemaManager(); + + if ($schemaManager->tablesExist(['lang', 'paste'])) { + $this->write('Copypaste1 tables detected. Skiping creation...'); + } else { + $this->write('Creating database in old format...'); + + $this->addSql( + 'CREATE TABLE `lang` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT \'ID\', + `name` varchar(100) CHARACTER SET utf8 NOT NULL COMMENT \'Language title for GUI\', + `file` varchar(24) CHARACTER SET utf8 NOT NULL COMMENT \'Language filename for GeSHi\', + `enabled` tinyint(1) unsigned NOT NULL COMMENT \'Is language usable or not\', + PRIMARY KEY (`id`), + KEY `lang_enabled` (`enabled`) + ) ENGINE=MyISAM AUTO_INCREMENT=190 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT=\'Programming languages\'' + ); + $this->addSql( + 'CREATE TABLE `paste` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT \'ID\', + `code` mediumtext CHARACTER SET utf8 NOT NULL COMMENT \'Code\', + `code_comment` text CHARACTER SET utf8 NOT NULL COMMENT \'Comments for code\', + `lang` int(11) unsigned NOT NULL COMMENT \'id языка ввода\', + `filename` varchar(128) CHARACTER SET utf8 NOT NULL COMMENT \'Filename\', + `name` varchar(48) CHARACTER SET utf8 NOT NULL COMMENT \'Author of quote name\', + `date_pub` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT \'Publish date\', + `date_exp` timestamp NOT NULL DEFAULT \'0000-00-00 00:00:00\' COMMENT \'Expire date\', + `ip` varchar(48) CHARACTER SET utf8 NOT NULL COMMENT \'IP\', + `secret` varchar(16) COLLATE utf8_unicode_ci NOT NULL COMMENT \'Paste secret\', + PRIMARY KEY (`id`), + KEY `expiration` (`date_exp`) + ) ENGINE=InnoDB AUTO_INCREMENT=1194 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' + ); + } + } + + public function down(Schema $schema) + { + $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('DROP TABLE lang'); + $this->addSql('DROP TABLE paste'); + } +} diff --git a/app/config/config.yml b/app/config/config.yml index bf4da51..b916725 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -64,6 +64,12 @@ doctrine: auto_generate_proxy_classes: "%kernel.debug%" auto_mapping: true +doctrine_migrations: + dir_name: %kernel.root_dir%/DoctrineMigrations + namespace: Application\Migrations + table_name: migration_versions + name: Application Migrations + # Swiftmailer Configuration swiftmailer: transport: "%mailer_transport%" diff --git a/composer.json b/composer.json index 5d5968b..e75cc92 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,9 @@ "symfony/monolog-bundle": "~2.4", "sensio/distribution-bundle": "~3.0,>=3.0.12", "sensio/framework-extra-bundle": "~3.0,>=3.0.2", - "incenteev/composer-parameter-handler": "~2.0" + "incenteev/composer-parameter-handler": "~2.0", + "doctrine/migrations": "1.0.*@dev", + "doctrine/doctrine-migrations-bundle": "2.1.*@dev" }, "require-dev": { "sensio/generator-bundle": "~2.3" diff --git a/composer.lock b/composer.lock index a6013e9..c0f9202 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "73f15ad91f600008506b4294b7b7d01c", + "hash": "5fc11fb887ef6aed953b90118745b7f8", "packages": [ { "name": "doctrine/annotations", @@ -514,6 +514,65 @@ ], "time": "2014-11-28 09:43:36" }, + { + "name": "doctrine/doctrine-migrations-bundle", + "version": "dev-master", + "target-dir": "Doctrine/Bundle/MigrationsBundle", + "source": { + "type": "git", + "url": "https://github.com/doctrine/DoctrineMigrationsBundle.git", + "reference": "6a1bd731dbdd4ad952a3b246a8f38c9c12f52e62" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/DoctrineMigrationsBundle/zipball/6a1bd731dbdd4ad952a3b246a8f38c9c12f52e62", + "reference": "6a1bd731dbdd4ad952a3b246a8f38c9c12f52e62", + "shasum": "" + }, + "require": { + "doctrine/doctrine-bundle": "~1.0", + "doctrine/migrations": "~1.0@dev", + "php": ">=5.3.2", + "symfony/framework-bundle": "~2.1" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Bundle\\MigrationsBundle": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Doctrine Project", + "homepage": "http://www.doctrine-project.org" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony DoctrineMigrationsBundle", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "dbal", + "migrations", + "schema" + ], + "time": "2015-02-16 13:24:46" + }, { "name": "doctrine/inflector", "version": "v1.0.1", @@ -635,6 +694,64 @@ ], "time": "2014-09-09 13:34:57" }, + { + "name": "doctrine/migrations", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/doctrine/migrations.git", + "reference": "058a4635ac9b80a5b1997df28a754e64b1425a1d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/migrations/zipball/058a4635ac9b80a5b1997df28a754e64b1425a1d", + "reference": "058a4635ac9b80a5b1997df28a754e64b1425a1d", + "shasum": "" + }, + "require": { + "doctrine/dbal": "~2.0", + "php": ">=5.3.2" + }, + "require-dev": { + "symfony/console": "2.*", + "symfony/yaml": "2.*" + }, + "suggest": { + "symfony/console": "to run the migration from the console" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\DBAL\\Migrations": "lib" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1" + ], + "authors": [ + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } + ], + "description": "Database Schema migrations using Doctrine DBAL", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "database", + "migrations" + ], + "time": "2015-02-19 08:13:05" + }, { "name": "doctrine/orm", "version": "v2.4.7", @@ -1667,7 +1784,9 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": { - "symfony/symfony": 20 + "symfony/symfony": 20, + "doctrine/migrations": 20, + "doctrine/doctrine-migrations-bundle": 20 }, "prefer-stable": false, "prefer-lowest": false, From 03baa5bb6c2046c8fb6286eb602cddaf368fd567 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Mon, 2 Mar 2015 22:25:59 +0300 Subject: [PATCH 3/6] New migration. Updates tables names, columns names and settings. --- .../Version20150302213116.php | 85 +++++++++++++++++++ .../Entity/{Paste.php => Copypaste.php} | 22 ++--- .../Entity/{Lang.php => Language.php} | 10 +-- 3 files changed, 101 insertions(+), 16 deletions(-) create mode 100644 app/DoctrineMigrations/Version20150302213116.php rename src/Skobkin/Bundle/CopyPasteBundle/Entity/{Paste.php => Copypaste.php} (88%) rename src/Skobkin/Bundle/CopyPasteBundle/Entity/{Lang.php => Language.php} (92%) diff --git a/app/DoctrineMigrations/Version20150302213116.php b/app/DoctrineMigrations/Version20150302213116.php new file mode 100644 index 0000000..741d8ba --- /dev/null +++ b/app/DoctrineMigrations/Version20150302213116.php @@ -0,0 +1,85 @@ +abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + // Tables structure + $this->write('Upgrading column names and setting...'); + + $this->addSql( + 'ALTER TABLE lang + CHANGE id id INT AUTO_INCREMENT NOT NULL, + CHANGE name name VARCHAR(100) NOT NULL, + CHANGE file code VARCHAR(24) NOT NULL, + CHANGE enabled enabled TINYINT(1) NOT NULL' + ); + $this->addSql('CREATE INDEX idx_code ON lang (code)'); + + $this->addSql( + 'ALTER TABLE paste + CHANGE id id INT AUTO_INCREMENT NOT NULL, + CHANGE code text LONGTEXT NOT NULL, + CHANGE code_comment description LONGTEXT DEFAULT NULL, + CHANGE lang language INT NOT NULL, + CHANGE filename file_name VARCHAR(128) DEFAULT NULL, + CHANGE name author VARCHAR(48) DEFAULT NULL, + CHANGE date_pub date_publish DATETIME NOT NULL, + CHANGE date_exp date_expire DATETIME DEFAULT NULL, + CHANGE ip ip VARCHAR(48) NOT NULL, + CHANGE secret secret VARCHAR(16) DEFAULT NULL' + ); + + // Renaming tables + $this->write('Renaming tables to the full name format...'); + $this->addSql('RENAME TABLE lang TO languages'); + $this->addSql('RENAME TABLE paste TO copypastes'); + } + + public function down(Schema $schema) + { + $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + // Tables structure + $this->write('Downgrading column names and setting...'); + + $this->addSql('DROP INDEX idx_code ON languages'); + $this->addSql( + 'ALTER TABLE lang + CHANGE id id INT UNSIGNED AUTO_INCREMENT NOT NULL COMMENT \'ID\', + CHANGE name name VARCHAR(100) NOT NULL, + CHANGE code file VARCHAR(24) NOT NULL, + CHANGE enabled enabled TINYINT(1) NOT NULL COMMENT \'Is language usable\'' + ); + + $this->addSql( + 'ALTER TABLE paste + CHANGE id id INT AUTO_INCREMENT NOT NULL, + CHANGE text code LONGTEXT NOT NULL COMMENT \'Code\', + CHANGE description code_comment LONGTEXT NOT NULL COMMENT \'Comments for code\', + CHANGE language lang INT UNSIGNED NOT NULL COMMENT \'Language ID\', + CHANGE file_name filename VARCHAR(128) NOT NULL COMMENT \'Filename\', + CHANGE id id INT UNSIGNED AUTO_INCREMENT NOT NULL COMMENT \'ID\', + CHANGE author name VARCHAR(48) NOT NULL COMMENT \'Author of quote name\', + CHANGE date_publish date_pub DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT \'Publish date\', + CHANGE date_expire date_exp DATETIME DEFAULT \'0000-00-00 00:00:00\' NOT NULL COMMENT \'Expire date\', + CHANGE ip ip varchar(48) NOT NULL COMMENT \'IP\', + CHANGE secret secret VARCHAR(16) NOT NULL COMMENT \'Paste secret\'' + ); + + // Renaming tables + $this->write('Renaming tables to the old short format...'); + $this->addSql('RENAME TABLE languages TO lang'); + $this->addSql('RENAME TABLE paste TO copypastes'); + } +} diff --git a/src/Skobkin/Bundle/CopyPasteBundle/Entity/Paste.php b/src/Skobkin/Bundle/CopyPasteBundle/Entity/Copypaste.php similarity index 88% rename from src/Skobkin/Bundle/CopyPasteBundle/Entity/Paste.php rename to src/Skobkin/Bundle/CopyPasteBundle/Entity/Copypaste.php index d8d5035..97496d2 100644 --- a/src/Skobkin/Bundle/CopyPasteBundle/Entity/Paste.php +++ b/src/Skobkin/Bundle/CopyPasteBundle/Entity/Copypaste.php @@ -5,17 +5,17 @@ namespace Skobkin\Bundle\CopyPasteBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** - * Paste + * Copypaste * * @ORM\Table( - * name="paste", + * name="copypastes", * indexes={ - * @ORM\Index(name="idx_expire", columns={"date_exp"}) + * @ORM\Index(name="idx_expire", columns={"date_expire"}) * } * ) * @ORM\Entity */ -class Paste +class Copypaste { /** * @var integer @@ -29,49 +29,49 @@ class Paste /** * @var string * - * @ORM\Column(name="code", type="text", nullable=false) + * @ORM\Column(name="text", type="text", nullable=false) */ private $text; /** * @var string * - * @ORM\Column(name="code_comment", type="text", nullable=true) + * @ORM\Column(name="description", type="text", nullable=true) */ private $description; /** * @var integer * - * @ORM\Column(name="lang", type="integer", nullable=false) + * @ORM\Column(name="language", type="integer", nullable=false) */ private $language; /** * @var string * - * @ORM\Column(name="filename", type="string", length=128, nullable=true) + * @ORM\Column(name="file_name", type="string", length=128, nullable=true) */ private $fileName; /** * @var string * - * @ORM\Column(name="name", type="string", length=48, nullable=true) + * @ORM\Column(name="author", type="string", length=48, nullable=true) */ private $author; /** * @var \DateTime * - * @ORM\Column(name="date_pub", type="datetime", nullable=false) + * @ORM\Column(name="date_publish", type="datetime", nullable=false) */ private $datePublished; /** * @var \DateTime * - * @ORM\Column(name="date_exp", type="datetime", nullable=true) + * @ORM\Column(name="date_expire", type="datetime", nullable=true) */ private $dateExpire; diff --git a/src/Skobkin/Bundle/CopyPasteBundle/Entity/Lang.php b/src/Skobkin/Bundle/CopyPasteBundle/Entity/Language.php similarity index 92% rename from src/Skobkin/Bundle/CopyPasteBundle/Entity/Lang.php rename to src/Skobkin/Bundle/CopyPasteBundle/Entity/Language.php index 38af62b..8ef60a1 100644 --- a/src/Skobkin/Bundle/CopyPasteBundle/Entity/Lang.php +++ b/src/Skobkin/Bundle/CopyPasteBundle/Entity/Language.php @@ -5,18 +5,18 @@ namespace Skobkin\Bundle\CopyPasteBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** - * Lang + * Language * * @ORM\Table( - * name="lang", + * name="languages", * indexes={ * @ORM\Index(name="idx_enabled", columns={"enabled"}), - * @ORM\Index(name="idx_file", columns={"file"}) + * @ORM\Index(name="idx_code", columns={"code"}) * } * ) * @ORM\Entity */ -class Lang +class Language { /** * @var integer @@ -37,7 +37,7 @@ class Lang /** * @var string * - * @ORM\Column(name="file", type="string", length=24, nullable=false) + * @ORM\Column(name="code", type="string", length=24, nullable=false) */ private $code; From a79d56d9734993df4741ad4880ca512180bc5a42 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Mon, 2 Mar 2015 23:12:49 +0300 Subject: [PATCH 4/6] New migration. Copypaste table now have foreign key for languages. --- .../Version20150302213116.php | 2 +- .../Version20150302223210.php | 39 +++++++++++++++++++ .../CopyPasteBundle/Entity/Copypaste.php | 11 +++--- 3 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 app/DoctrineMigrations/Version20150302223210.php diff --git a/app/DoctrineMigrations/Version20150302213116.php b/app/DoctrineMigrations/Version20150302213116.php index 741d8ba..b7a8634 100644 --- a/app/DoctrineMigrations/Version20150302213116.php +++ b/app/DoctrineMigrations/Version20150302213116.php @@ -6,7 +6,7 @@ use Doctrine\DBAL\Migrations\AbstractMigration; use Doctrine\DBAL\Schema\Schema; /** - * Auto-generated Migration: Please modify to your needs! + * Updating tables and column names */ class Version20150302213116 extends AbstractMigration { diff --git a/app/DoctrineMigrations/Version20150302223210.php b/app/DoctrineMigrations/Version20150302223210.php new file mode 100644 index 0000000..eaaef21 --- /dev/null +++ b/app/DoctrineMigrations/Version20150302223210.php @@ -0,0 +1,39 @@ +abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->write('Converting languages table to InnoDB format...'); + $this->addSql('ALTER TABLE languages ENGINE=InnoDB'); + $this->write('Updating copypaste table structure...'); + $this->addSql('ALTER TABLE copypastes CHANGE language language_id INT DEFAULT NULL'); + $this->write('Adding foreign key...'); + $this->addSql('ALTER TABLE copypastes ADD CONSTRAINT FK_DBA4BEBE82F1BAF4 FOREIGN KEY (language_id) REFERENCES languages (id)'); + $this->write('Creating copypaste language index...'); + $this->addSql('CREATE INDEX IDX_DBA4BEBE82F1BAF4 ON copypastes (language_id)'); + } + + public function down(Schema $schema) + { + $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->write('Dropping foreign key...'); + $this->addSql('ALTER TABLE copypastes DROP FOREIGN KEY FK_DBA4BEBE82F1BAF4'); + $this->write('Dropping copypaste language index...'); + $this->addSql('DROP INDEX IDX_DBA4BEBE82F1BAF4 ON copypastes'); + $this->addSql('ALTER TABLE copypastes CHANGE language_id language INT NOT NULL, DROP language_id'); + $this->write('Converting languages table to MyISAM format...'); + $this->addSql('ALTER TABLE languages ENGINE=MyISAM'); + } +} diff --git a/src/Skobkin/Bundle/CopyPasteBundle/Entity/Copypaste.php b/src/Skobkin/Bundle/CopyPasteBundle/Entity/Copypaste.php index 97496d2..ed58077 100644 --- a/src/Skobkin/Bundle/CopyPasteBundle/Entity/Copypaste.php +++ b/src/Skobkin/Bundle/CopyPasteBundle/Entity/Copypaste.php @@ -41,9 +41,10 @@ class Copypaste private $description; /** - * @var integer + * @var Language * - * @ORM\Column(name="language", type="integer", nullable=false) + * @ORM\ManyToOne(targetEntity="Language") + * @ORM\JoinColumn(name="language_id", referencedColumnName="id") */ private $language; @@ -138,7 +139,7 @@ class Copypaste } /** - * Get codeComment + * Get code description * * @return string */ @@ -240,7 +241,7 @@ class Copypaste } /** - * Set dateExp + * Set expiration date * * @param \DateTime $dateExpire * @return Paste @@ -253,7 +254,7 @@ class Copypaste } /** - * Get dateExp + * Get expiration date * * @return \DateTime */ From c3c801ddeced56c2b6e07ae34d4190f1b7369a30 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Mon, 2 Mar 2015 23:40:29 +0300 Subject: [PATCH 5/6] Doctrine Fixtures installed. GeSHi installed. Fixture for language import implemented. --- app/AppKernel.php | 2 + composer.json | 5 +- composer.lock | 202 +++++++++++++++++- .../DataFixtures/ORM/LoadLanguages.php | 98 +++++++++ 4 files changed, 304 insertions(+), 3 deletions(-) create mode 100644 src/Skobkin/Bundle/CopyPasteBundle/DataFixtures/ORM/LoadLanguages.php diff --git a/app/AppKernel.php b/app/AppKernel.php index a75d4a0..9be1531 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -16,7 +16,9 @@ class AppKernel extends Kernel new Symfony\Bundle\AsseticBundle\AsseticBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(), + new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), + new DT\Bundle\GeshiBundle\DTGeshiBundle(), new Skobkin\Bundle\CopyPasteBundle\SkobkinCopyPasteBundle(), ); diff --git a/composer.json b/composer.json index e75cc92..f675302 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,10 @@ "sensio/framework-extra-bundle": "~3.0,>=3.0.2", "incenteev/composer-parameter-handler": "~2.0", "doctrine/migrations": "1.0.*@dev", - "doctrine/doctrine-migrations-bundle": "2.1.*@dev" + "doctrine/doctrine-migrations-bundle": "2.1.*@dev", + "doctrine/doctrine-fixtures-bundle": "2.2.*", + "theodordiaconu/geshi": "dev-master", + "theodordiaconu/geshi-bundle" : "dev-master" }, "require-dev": { "sensio/generator-bundle": "~2.3" diff --git a/composer.lock b/composer.lock index c0f9202..071deca 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "5fc11fb887ef6aed953b90118745b7f8", + "hash": "e36598c346f19a7d683f1c1f3d58399f", "packages": [ { "name": "doctrine/annotations", @@ -290,6 +290,62 @@ ], "time": "2014-05-21 19:28:51" }, + { + "name": "doctrine/data-fixtures", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/data-fixtures.git", + "reference": "b4a135c7db56ecc4602b54a2184368f440cac33e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/data-fixtures/zipball/b4a135c7db56ecc4602b54a2184368f440cac33e", + "reference": "b4a135c7db56ecc4602b54a2184368f440cac33e", + "shasum": "" + }, + "require": { + "doctrine/common": ">=2.2,<2.5-dev", + "php": ">=5.3.2" + }, + "require-dev": { + "doctrine/orm": ">=2.2,<2.5-dev" + }, + "suggest": { + "doctrine/mongodb-odm": "For loading MongoDB ODM fixtures", + "doctrine/orm": "For loading ORM fixtures", + "doctrine/phpcr-odm": "For loading PHPCR ODM fixtures" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\DataFixtures": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com", + "homepage": "http://www.jwage.com/", + "role": "Creator" + } + ], + "description": "Data Fixtures for all Doctrine Object Managers", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "database" + ], + "time": "2013-07-10 17:04:07" + }, { "name": "doctrine/dbal", "version": "v2.4.4", @@ -514,6 +570,66 @@ ], "time": "2014-11-28 09:43:36" }, + { + "name": "doctrine/doctrine-fixtures-bundle", + "version": "v2.2.0", + "target-dir": "Doctrine/Bundle/FixturesBundle", + "source": { + "type": "git", + "url": "https://github.com/doctrine/DoctrineFixturesBundle.git", + "reference": "c811f96f0cf83b997e3a3ed037cac729bbe3e803" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/DoctrineFixturesBundle/zipball/c811f96f0cf83b997e3a3ed037cac729bbe3e803", + "reference": "c811f96f0cf83b997e3a3ed037cac729bbe3e803", + "shasum": "" + }, + "require": { + "doctrine/data-fixtures": "~1.0", + "doctrine/doctrine-bundle": "~1.0", + "php": ">=5.3.2", + "symfony/doctrine-bridge": "~2.1" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Bundle\\FixturesBundle": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Doctrine Project", + "homepage": "http://www.doctrine-project.org" + } + ], + "description": "Symfony DoctrineFixturesBundle", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "Fixture", + "persistence" + ], + "time": "2013-09-05 11:23:37" + }, { "name": "doctrine/doctrine-migrations-bundle", "version": "dev-master", @@ -1621,6 +1737,86 @@ ], "time": "2015-03-02 10:21:01" }, + { + "name": "theodordiaconu/geshi", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/theodorDiaconu/geshi.git", + "reference": "c2a5294496b34d7561db5c0641b7f960d930f6b1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theodorDiaconu/geshi/zipball/c2a5294496b34d7561db5c0641b7f960d930f6b1", + "reference": "c2a5294496b34d7561db5c0641b7f960d930f6b1", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "GeSHi": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Geshi library", + "homepage": "http://qbnz.com/highlighter/", + "keywords": [ + "Symfony2", + "geshi", + "highlighter" + ], + "time": "2013-03-19 00:39:21" + }, + { + "name": "theodordiaconu/geshi-bundle", + "version": "dev-master", + "target-dir": "DT/Bundle/GeshiBundle", + "source": { + "type": "git", + "url": "https://github.com/theodorDiaconu/geshi-bundle.git", + "reference": "4606ec8c7e338054f589147a6a6e1355f7262094" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theodorDiaconu/geshi-bundle/zipball/4606ec8c7e338054f589147a6a6e1355f7262094", + "reference": "4606ec8c7e338054f589147a6a6e1355f7262094", + "shasum": "" + }, + "require": { + "theodordiaconu/geshi": "dev-master" + }, + "type": "symfony-bundle", + "autoload": { + "psr-0": { + "DT\\Bundle\\GeshiBundle": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Theodor Diaconu", + "email": "diaconu.theodor@gmail.com" + } + ], + "description": "Symfony GeshiBundle", + "homepage": "http://www.datati.ro", + "keywords": [ + "geshi", + "highlight", + "highlighter", + "syntax highlight" + ], + "time": "2013-03-29 12:54:06" + }, { "name": "twig/extensions", "version": "v1.2.0", @@ -1786,7 +1982,9 @@ "stability-flags": { "symfony/symfony": 20, "doctrine/migrations": 20, - "doctrine/doctrine-migrations-bundle": 20 + "doctrine/doctrine-migrations-bundle": 20, + "theodordiaconu/geshi": 20, + "theodordiaconu/geshi-bundle": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/src/Skobkin/Bundle/CopyPasteBundle/DataFixtures/ORM/LoadLanguages.php b/src/Skobkin/Bundle/CopyPasteBundle/DataFixtures/ORM/LoadLanguages.php new file mode 100644 index 0000000..bb8b8b9 --- /dev/null +++ b/src/Skobkin/Bundle/CopyPasteBundle/DataFixtures/ORM/LoadLanguages.php @@ -0,0 +1,98 @@ +container = $container; + } + + /** + * {@inheritDoc} + */ + public function load(ObjectManager $manager) + { + $output = new ConsoleOutput(); + + $geshiPath = $this->container->get('kernel')->getRootDir() . '/../vendor/theodordiaconu/geshi/src/GeSHi/geshi'; + + $finder = new Finder(); + $finder->files()->in($geshiPath); + + // Fix constants + define('GESHI_CAPS_NO_CHANGE', true); + define('GESHI_COMMENTS', true); + define('GESHI_NEVER', true); + define('GESHI_SEARCH', true); + define('GESHI_REPLACE', true); + define('GESHI_MODIFIERS', true); + define('GESHI_BEFORE', true); + define('GESHI_AFTER', true); + define('GESHI_MAYBE', true); + define('GESHI_NUMBER_INT_BASIC', true); + define('GESHI_NUMBER_HEX_PREFIX_DOLLAR', true); + define('GESHI_NUMBER_BIN_PREFIX_PERCENT', true); + define('GESHI_NUMBER_FLT_NONSCI', true); + define('GESHI_NUMBER_HEX_PREFIX', true); + define('GESHI_NUMBER_FLT_SCI_ZERO', true); + define('GESHI_NUMBER_OCT_PREFIX', true); + define('GESHI_ALWAYS', true); + define('GESHI_CAPS_UPPER', true); + define('GESHI_NUMBER_FLT_NONSCI_F', true); + define('GESHI_NUMBER_FLT_SCI_SHORT', true); + define('GESHI_NUMBER_HEX_SUFFIX', true); + define('GESHI_NUMBER_INT_CSTYLE', true); + define('GESHI_NUMBER_BIN_PREFIX_0B', true); + define('GESHI_NUMBER_BIN_SUFFIX', true); + define('GESHI_NUMBER_OCT_SUFFIX', true); + define('GESHI_CLASS', true); + define('GESHI_NUMBER_OCT_PREFIX_0O', true); + define('GESHI_NUMBER_OCT_PREFIX_AT', true); + + /* @var $file SplFileInfo */ + foreach ($finder as $file) { + $output->writeln($file->getRelativePathname() . ' found. Parsing...'); + + include $geshiPath . DIRECTORY_SEPARATOR .$file->getRelativePathname(); + + $language = new Language(); + $language + ->setName($language_data['LANG_NAME']) + ->setCode(basename($file->getRelativePathname(), '.php')) + ->setEnabled(true) + ; + + $output->write('---> "' . $language->getName() . '"'); + $manager->persist($language); + $manager->flush(); + $output->writeln(' [ PERSISTED ]'); + } + + $output->writeln('Import finished!'); + } +} From e9713f886d12737744f2e09efc384572395f345c Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Tue, 3 Mar 2015 01:24:09 +0300 Subject: [PATCH 6/6] Cron command for expired entities. --- .../Command/DropExpiredCopypastesCommand.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/Skobkin/Bundle/CopyPasteBundle/Command/DropExpiredCopypastesCommand.php diff --git a/src/Skobkin/Bundle/CopyPasteBundle/Command/DropExpiredCopypastesCommand.php b/src/Skobkin/Bundle/CopyPasteBundle/Command/DropExpiredCopypastesCommand.php new file mode 100644 index 0000000..f165b6a --- /dev/null +++ b/src/Skobkin/Bundle/CopyPasteBundle/Command/DropExpiredCopypastesCommand.php @@ -0,0 +1,41 @@ +setName('copypaste:cron:drop-expired') + ->setDescription('Drop expired copypastes') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $output->write('Deleting expired entities...'); + + /* @var $em EntityManager */ + $em = $this->getContainer()->get('doctrine')->getManager(); + $queryBuilder = $em->createQueryBuilder() + ->delete('SkobkinCopyPasteBundle:Copypaste c') + ->where('c.dateExpire < :now') + ->setParameter('now', new \DateTime()); + $queryBuilder->getQuery()->execute(); + + $output->writeln('Done.'); + } +}