Merged in database (pull request #1) Common database code implemented

This commit is contained in:
Alexey Skobkin 2015-03-03 17:53:27 +03:00
commit b4ee4312bb
11 changed files with 1119 additions and 3 deletions

View File

@ -15,7 +15,10 @@ 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 Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new DT\Bundle\GeshiBundle\DTGeshiBundle(),
new Skobkin\Bundle\CopyPasteBundle\SkobkinCopyPasteBundle(),
);

View File

@ -0,0 +1,60 @@
<?php
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* First migration. Creates new database in copypaste1 format or skipping creation if data already exists.
*/
class Version20150302205121 extends AbstractMigration
{
public function up(Schema $schema)
{
$this->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');
}
}

View File

@ -0,0 +1,85 @@
<?php
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Updating tables and column names
*/
class Version20150302213116 extends AbstractMigration
{
public function up(Schema $schema)
{
$this->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');
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Converting languages to the InnoDB and adding foreign key
*/
class Version20150302223210 extends AbstractMigration
{
public function up(Schema $schema)
{
$this->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');
}
}

View File

@ -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%"

View File

@ -18,7 +18,12 @@
"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",
"doctrine/doctrine-fixtures-bundle": "2.2.*",
"theodordiaconu/geshi": "dev-master",
"theodordiaconu/geshi-bundle" : "dev-master"
},
"require-dev": {
"sensio/generator-bundle": "~2.3"

321
composer.lock generated
View File

@ -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": "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,125 @@
],
"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",
"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 +810,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",
@ -1504,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",
@ -1667,7 +1980,11 @@
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"symfony/symfony": 20
"symfony/symfony": 20,
"doctrine/migrations": 20,
"doctrine/doctrine-migrations-bundle": 20,
"theodordiaconu/geshi": 20,
"theodordiaconu/geshi-bundle": 20
},
"prefer-stable": false,
"prefer-lowest": false,

View File

@ -0,0 +1,41 @@
<?php
namespace Skobkin\Bundle\CopyPasteBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\ORM\EntityManager;
/**
* Deleting expired copypastes by Cron
*
* @author Alexey Skobkin
*/
class DropExpiredCopypastesCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->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.');
}
}

View File

@ -0,0 +1,98 @@
<?php
namespace Skobkin\Bundle\CopyPasteBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\Query;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Skobkin\Bundle\CopyPasteBundle\Entity\Language;
/**
* Description of LoadLanguages
*
* @author Alexey Skobkin
*/
class LoadLanguages implements FixtureInterface, ContainerAwareInterface
{
/**
* @var ContainerInterface
*/
private $container;
/**
* {@inheritDoc}
*/
public function setContainer(ContainerInterface $container = null)
{
$this->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!');
}
}

View File

@ -0,0 +1,321 @@
<?php
namespace Skobkin\Bundle\CopyPasteBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Copypaste
*
* @ORM\Table(
* name="copypastes",
* indexes={
* @ORM\Index(name="idx_expire", columns={"date_expire"})
* }
* )
* @ORM\Entity
*/
class Copypaste
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="text", type="text", nullable=false)
*/
private $text;
/**
* @var string
*
* @ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* @var Language
*
* @ORM\ManyToOne(targetEntity="Language")
* @ORM\JoinColumn(name="language_id", referencedColumnName="id")
*/
private $language;
/**
* @var string
*
* @ORM\Column(name="file_name", type="string", length=128, nullable=true)
*/
private $fileName;
/**
* @var string
*
* @ORM\Column(name="author", type="string", length=48, nullable=true)
*/
private $author;
/**
* @var \DateTime
*
* @ORM\Column(name="date_publish", type="datetime", nullable=false)
*/
private $datePublished;
/**
* @var \DateTime
*
* @ORM\Column(name="date_expire", type="datetime", nullable=true)
*/
private $dateExpire;
/**
* @var string
*
* @ORM\Column(name="ip", type="string", length=48, nullable=false)
*/
private $ip;
/**
* @var string
*
* @ORM\Column(name="secret", type="string", length=16, nullable=true)
*/
private $secret;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->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 code description
*
* @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 expiration date
*
* @param \DateTime $dateExpire
* @return Paste
*/
public function setDateExpire($dateExpire)
{
$this->dateExpire = $dateExpire;
return $this;
}
/**
* Get expiration date
*
* @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;
}
}

View File

@ -0,0 +1,141 @@
<?php
namespace Skobkin\Bundle\CopyPasteBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Language
*
* @ORM\Table(
* name="languages",
* indexes={
* @ORM\Index(name="idx_enabled", columns={"enabled"}),
* @ORM\Index(name="idx_code", columns={"code"})
* }
* )
* @ORM\Entity
*/
class Language
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=100, nullable=false)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="code", type="string", length=24, nullable=false)
*/
private $code;
/**
* @var boolean
*
* @ORM\Column(name="enabled", type="boolean", nullable=false)
*/
private $enabled;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->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;
}
}