/**
  * Inialise a Doctrine 1 connection.
  *
  * Listens for 'doctrine.init_connection' events.
  *
  * Event arguments are:
  * boolean 'lazy'  - lazy connect.
  * string 'name' - connection name.
  *
  * @param Zikula_Event $event Event.
  *
  * @return void
  */
 public function doctrineInit(Zikula_Event $event)
 {
     if (!$this->doctrineManager) {
         Doctrine_Core::debug(System::isDevelopmentMode());
         $this->doctrineManager = Doctrine_Manager::getInstance();
         $internalEvent = new Zikula_Event('doctrine.configure', $this->doctrineManager);
         $this->eventManager->notify($internalEvent);
         $internalEvent = new Zikula_Event('doctrine.cache', $this->doctrineManager);
         $this->eventManager->notify($internalEvent);
     }
     $lazyConnect = isset($event['lazy']) ? $event['lazy'] : false;
     $name = isset($event['name']) ? $event['name'] : 'default';
     $connectionInfo = $this->serviceManager['databases'][$name];
     // test the DB connection works or just set lazy
     try {
         if ($lazyConnect) {
             $dsn = "{$connectionInfo['dbdriver']}://{$connectionInfo['user']}:{$connectionInfo['password']}@{$connectionInfo['host']}/{$connectionInfo['dbname']}";
             $connection = Doctrine_Manager::connection($dsn, $name);
         } else {
             $dbh = new PDO("{$connectionInfo['dbdriver']}:host={$connectionInfo['host']};dbname={$connectionInfo['dbname']}", $connectionInfo['user'], $connectionInfo['password']);
             $connection = Doctrine_Manager::connection($dbh, $name);
             $connection->setOption('username', $connectionInfo['user']);
             $connection->setOption('password', $connectionInfo['password']);
         }
         $internalEvent = new Zikula_Event('doctrine.configure', $connection);
         $this->eventManager->notify($internalEvent);
     } catch (PDOException $e) {
         throw new PDOException(__('Connection failed to database') . ': ' . $e->getMessage());
     }
     // set mysql engine type
     if ($connectionInfo['dbdriver'] == 'mysql') {
         $connection->setAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_TYPE, $connectionInfo['dbtabletype']);
     }
     try {
         if (isset($connectionInfo['charset'])) {
             $connection->setCharset($connectionInfo['charset']);
         }
         if (isset($connectionInfo['collate'])) {
             $connection->setCollate($connectionInfo['collate']);
         }
     } catch (Exception $e) {
         //if (!System::isInstalling()) {
         //    throw new Exception(__('Error setting database characterset and collation.'));
         //}
     }
     if ($connectionInfo['dbdriver'] != 'oracle') {
         $connection->setAttribute(Doctrine_Core::ATTR_PORTABILITY, Doctrine_Core::PORTABILITY_ALL ^ Doctrine_Core::PORTABILITY_EMPTY_TO_NULL);
     }
     if (isset($this->serviceManager['log.enabled']) && $this->serviceManager['log.enabled']) {
         // add listener that sends events for all sql queries
         $connection->setListener(new Zikula_Doctrine_Listener_Profiler());
     }
     $event->data = $connection;
 }
 public function configureDoctrine(Doctrine_Manager $manager)
 {
     Doctrine_Core::debug(sfConfig::get('dm_debug'));
     /*
      * Configure inheritance
      */
     $manager->setAttribute(Doctrine_Core::ATTR_TABLE_CLASS, 'myDoctrineTable');
     $manager->setAttribute(Doctrine_Core::ATTR_QUERY_CLASS, 'myDoctrineQuery');
     $manager->setAttribute(Doctrine_Core::ATTR_COLLECTION_CLASS, 'myDoctrineCollection');
     /*
      * Configure charset
      */
     $manager->setCharset('utf8');
     $manager->setCollate('utf8_unicode_ci');
     /*
      * Configure hydrators
      */
     $manager->registerHydrator('dmFlat', 'Doctrine_Hydrator_dmFlatDriver');
     /*
      * Configure builder
      */
     sfConfig::set('doctrine_model_builder_options', array('generateTableClasses' => true, 'baseClassName' => 'myDoctrineRecord', 'baseTableClassName' => 'myDoctrineTable', 'suffix' => '.class.php'));
 }
Exemple #3
0
 /**
  * Formats, and then returns, the message in the specified exception
  *
  * @param  Exception $exception
  * @return string
  */
 protected function formatExceptionMessage(Exception $exception)
 {
     $message = $exception->getMessage();
     if (Doctrine_Core::debug()) {
         $message .= "\n" . $exception->getTraceAsString();
     }
     return $this->getFormatter()->format($message, 'ERROR') . "\n";
 }
 * obtain it through the world-wide-web, please send an email
 * to blipoteka@gmail.com so we can send you a copy immediately.
 *
 * @category   Blipoteka
 * @package    Blipoteka_Scripts
 * @copyright  Copyright (c) 2010-2011 Jakub Argasiński (argasek@gmail.com)
 * @license    http://blipoteka.pl/license Simplified BSD License
 */

if (!defined('APPLICATION_DOCTRINE_SCRIPT')) {
	echo "This script should not be executed directly.\n";
	exit(0);
}

define('APPLICATION_ENV', getenv('APPLICATION_ENV') ?: 'cli');
defined('DS') || define('DS', DIRECTORY_SEPARATOR);

include __DIR__ . DS . '..' . DS . 'public' . DS . 'initenv.php';

$bootstrap = $application->bootstrap('doctrine')->getBootstrap();
$doctrine = $bootstrap->getResource('doctrine');

Doctrine_Core::debug(true);

// PEAR style loading -- prevents Doctrine's premature e*********n
$doctrineManager = $doctrine->getManager();
$doctrineManager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_PEAR);
$connectionOptions = $doctrineManager->getCurrentConnection()->getOptions();

echo sprintf("Environment: %s, DSN: '%s'\n", APPLICATION_ENV, $connectionOptions['dsn']);