среда, 20 июня 2012 г.
Blogothoughts: Установка и настройка utserver (utorrent) на ubunt...
Blogothoughts: Установка и настройка utserver (utorrent) на ubunt...: Вышла серверная (только консоль) Linux версия utorrent - а. Решил поставить посмотреть как она смотрится.
четверг, 14 июня 2012 г.
SSH Forwarding
SSH Forwarding
service my
{
type = UNLISTED
flags = REUSE
socket_type = stream
wait = no
server = /bin/false
protocol = tcp
interface = 192.168.1.1
port = 1234
user = nobody
disable = no
redirect = 192.168.1.10 1234
log_type = FILE /var/log/redirect.log
log_on_success += HOST DURATION USERID TRAFFIC USERID
log_on_failure = HOST ATTEMPT USERID
only_from = 192.168.1.0/24
}
Jira Startup Errors
Confluence refuses to start with the following error message:
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
solution
https://confluence.atlassian.com/display/DOC/Fix+Out+of+Memory+Errors+by+Increasing+Available+Memory
пятница, 1 июня 2012 г.
Generate Doctrine2 Mappings From Existing Database
http://jejakroda.wordpress.com/2011/02/03/generate-doctrine2-mappings-from-existing-database/
Generate Doctrine2 Mappings From Existing Database
Object-Relational Mapping (ORM) is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a “virtual object database” that can be used from within the programming language. Doctrine is an ORM tool for PHP 5.2.3+ that sits on top of a database abstraction layer. It allows easy access to all types of databases, such as MySQL, through the use of PHP objects. Doctrine2 is the new generation of Doctrine.
Recently I needed to use Doctrine2 and I wanted to make annotated entities for mapping from existing database, because I already had the database schema. (I do not recommend this, though, since some suggest that it is better to make the entities first, or to use XML or YAML mappings.) Supposedly we can make mappings using the CLI, but we still need to make a script, so I prefer an all-script method to accomplish it. I googled for it and found a script by Daniel S. W., but it still had some errors. I edited a bit, and so here it is:
use Doctrine\ORM\Tools\EntityGenerator; ini_set("display_errors", "On"); // this is not necessary if you use Doctrine2 with PEAR //$libPath = __DIR__ . '/../lib/doctrine2'; // autoloaders require_once 'Doctrine/Common/ClassLoader.php'; //$classLoader = new \Doctrine\Common\ClassLoader('Doctrine', $libPath); // custom path $classLoader = new \Doctrine\Common\ClassLoader('Doctrine'); // with PEAR $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__); $classLoader->register(); // config $config = new \Doctrine\ORM\Configuration(); $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(__DIR__ . '/Entities')); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache); $config->setProxyDir(__DIR__ . '/Proxies'); $config->setProxyNamespace('Proxies'); $connectionParams = array( 'dbname' => 'xxx', 'user' => 'root', 'password' => '', 'host' => 'localhost', 'driver' => 'pdo_mysql', ); $em = \Doctrine\ORM\EntityManager::create($connectionParams, $config); // custom datatypes (not mapped for reverse engineering) $em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('set', 'string'); $em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); // fetch metadata $driver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver( $em->getConnection()->getSchemaManager() ); $em->getConfiguration()->setMetadataDriverImpl($driver); $cmf = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory(); $cmf->setEntityManager($em); // we must set the EntityManager $classes = $driver->getAllClassNames(); $metadata = array(); foreach ($classes as $class) { //any unsupported table/schema could be handled here to exclude some classes if (true) { $metadata[] = $cmf->getMetadataFor($class); } } $generator = new EntityGenerator(); $generator->setUpdateEntityIfExists(true); // only update if class already exists //$generator->setRegenerateEntityIfExists(true); // this will overwrite the existing classes $generator->setGenerateStubMethods(true); $generator->setGenerateAnnotations(true); $generator->generate($metadata, __DIR__ . '/Entities'); print 'Done!';
Command Line Interface
Like I said before, we can also use CLI to generate Doctrine2 mappings. To do this, however, we still need to make a configuration file named
cli-config.php
in the working folder. I took this code from Doctrine2 cookbook example (we actually don’t need some of the lines, I copy-pasted this from the file I have):require_once 'Doctrine/Common/ClassLoader.php'; // with PEAR // Setup Autoloader (1) // Define application environment define('APPLICATION_ENV', "development"); /* defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); */ // Autoloader (1) $classLoader = new \Doctrine\Common\ClassLoader('Doctrine'); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__); $classLoader->register(); // configuration (2) $config = new \Doctrine\ORM\Configuration(); // Proxies (3) $config->setProxyDir(__DIR__ . '/Proxies'); $config->setProxyNamespace('Proxies'); $config->setAutoGenerateProxyClasses((APPLICATION_ENV == "development")); // Driver (4) $driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__.DIRECTORY_SEPARATOR."Entities")); $config->setMetadataDriverImpl($driverImpl); // Caching Configuration (5) if (APPLICATION_ENV == "development") { $cache = new \Doctrine\Common\Cache\ArrayCache(); } else { $cache = new \Doctrine\Common\Cache\ApcCache(); } $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $connectionOptions = array( 'driver' => 'pdo_mysql', 'host' => 'localhost', 'dbname' => 'xxx', 'user' => 'root', 'password' => ''); $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config); $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array( 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em) ));
Now we can use the Doctrine2 CLI command. There’s a command to generate entities, orm:generate-entities, but it requires metadata classes. So we use another command to create mappings,orm:convert-mapping. I’m using XAMPP in Windows, so these steps are for Windows:
- Put
cli-config.php
to the folder where you will run the CLI command. - If you don’t want to set the
PATH
variable, just copy all files (doctrine.bat
,doctrine
,doctrine.php
) from Doctrine2′sbin
folder to your working folder. - You might want to create a folder to put the mapping files. I use a folder named
mapping
. - Now enter command prompt. Go to your working folder.
- Now we’re ready to use the CLI command. Add
php
at the beginning of every command line:php doctrine orm:convert-mapping --from-database annotation .\mapping
As you can see, I use the parameter--from-database
to create mapping from the database to annotated PHP files, which will be put in themapping
folder. You can also change the parameterannotation
toxml
oryml
to create mapping in XML and YAML, respectively.
The mapping files we get from this automated process are still half done, so we need to edit them to suit our needs. The output files from CLI command orm:convert-mapping don’t have setter and getter methods, while the ones from the first PHP script have. Either way we still have to add UNIQUE keys manually.
Подписаться на:
Сообщения (Atom)