コード例 #1
0
 /**
  * Initialise.
  *
  * Runs at plugin init time.
  *
  * @return void
  */
 public function initialize(GenericEvent $event)
 {
     // register namespace
     // Because the standard kernel classloader already has Doctrine registered as a namespace
     // we have to add a new loader onto the spl stack.
     $autoloader = new UniversalClassLoader();
     $autoloader->register();
     $autoloader->registerNamespaces(array('DoctrineProxy' => 'ztemp/doctrinemodels'));
     $container = $event->getDispatcher()->getContainer();
     $config = $GLOBALS['ZConfig']['DBInfo']['databases']['default'];
     $dbConfig = array('host' => $config['host'], 'user' => $config['user'], 'password' => $config['password'], 'dbname' => $config['dbname'], 'driver' => 'pdo_' . $config['dbdriver']);
     $r = new \ReflectionClass('Doctrine\\Common\\Cache\\' . $container['dbcache.type'] . 'Cache');
     $dbCache = $r->newInstance();
     $ORMConfig = new \Doctrine\ORM\Configuration();
     $container->set('doctrine.configuration', $ORMConfig);
     $ORMConfig->setMetadataCacheImpl($dbCache);
     // create proxy cache dir
     \CacheUtil::createLocalDir('doctrinemodels');
     // setup annotations base
     include_once \ZLOADER_PATH . '/../vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php';
     // setup annotation reader
     $reader = new \Doctrine\Common\Annotations\AnnotationReader();
     $cacheReader = new \Doctrine\Common\Annotations\CachedReader($reader, new \Doctrine\Common\Cache\ArrayCache());
     $container->set('doctrine.annotationreader', $cacheReader);
     // setup annotation driver
     $annotationDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($cacheReader);
     $container->set('doctrine.annotationdriver', $annotationDriver);
     // setup driver chains
     $driverChain = new \Doctrine\ORM\Mapping\Driver\DriverChain();
     $container->set('doctrine.driverchain', $driverChain);
     // configure Doctrine ORM
     $ORMConfig->setMetadataDriverImpl($annotationDriver);
     $ORMConfig->setQueryCacheImpl($dbCache);
     $ORMConfig->setProxyDir(\CacheUtil::getLocalDir('doctrinemodels'));
     $ORMConfig->setProxyNamespace('DoctrineProxy');
     if (isset($container['log.enabled']) && $container['log.enabled']) {
         $ORMConfig->setSQLLogger(new \Zikula\Core\Doctrine\Logger\ZikulaSqlLogger());
     }
     // setup doctrine eventmanager
     $dispatcher = new \Doctrine\Common\EventManager();
     $container->set('doctrine.eventmanager', $dispatcher);
     // setup MySQL specific listener (storage engine and encoding)
     if ($config['dbdriver'] == 'mysql') {
         $mysqlSessionInit = new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit($config['charset']);
         $dispatcher->addEventSubscriber($mysqlSessionInit);
     }
     // setup the doctrine entitymanager
     $entityManager = \Doctrine\ORM\EntityManager::create($dbConfig, $ORMConfig, $dispatcher);
     $container->set('doctrine.entitymanager', $entityManager);
 }
コード例 #2
0
ファイル: Categorisable.php プロジェクト: Silwereth/core
 /**
  * Generates an subclass of the Zikula_Doctrine_Model_EntityCategory class and caches the generated class in a file.
  *
  * @param string $module     Name of the Module to that the model belongs to.
  * @param string $modelClass Classname of the model.
  *
  * @return void
  * @throws Exception Throws when the create of the cache directory fails.
  */
 private static function _generateSubclassForCategorisableTemplate($module, $modelClass)
 {
     $table = Doctrine::getTable($modelClass);
     sscanf($table->getTableName(), Doctrine_Manager::getInstance()->getAttribute(Doctrine::ATTR_TBLNAME_FORMAT), $tableName);
     $dir = 'doctrinemodels/GeneratedDoctrineModel/' . str_replace('_', DIRECTORY_SEPARATOR, $modelClass);
     if (CacheUtil::createLocalDir($dir, ServiceUtil::getManager()->getParameter('system.chmod_dir'))) {
         $subclassName = 'GeneratedDoctrineModel_' . $modelClass . '_EntityCategory';
         $fileContents = '<?php class ' . $subclassName . ' extends Zikula_Doctrine_Model_EntityCategory { }';
         $fileName = 'EntityCategory.php';
         // save new model
         file_put_contents(CacheUtil::getLocalDir() . '/' . $dir . '/' . $fileName, $fileContents);
         // save required data for later use
         $modelsInfo = ModUtil::getVar('ZikulaCategoriesModule', 'EntityCategorySubclasses', array());
         $modelsInfo[$subclassName] = array('module' => $module, 'table' => $tableName);
         ModUtil::setVar('ZikulaCategoriesModule', 'EntityCategorySubclasses', $modelsInfo);
     } else {
         throw new Exception('Creation of the cache directory ' . $dir . ' failed');
     }
 }
コード例 #3
0
ファイル: User.php プロジェクト: projectesIF/Sirius
 /**
  * Check to see if file is cached and current
  * return false if !exists or !current
  * return full filepath if exists and current
  *
  * @param string $title
  * @return mixed boolean/string
  */
 private function pdfIsCached($title)
 {
     $dir = CacheUtil::getLocalDir('NewsPDF');
     if (!is_dir($dir)) {
         CacheUtil::createLocalDir('NewsPDF', 0755, true);
     }
     $title = $title . '.pdf';
     // modify title like the tcpdf::Output() method does
     $title = preg_replace('/[\s]+/', '_', $title);
     $title = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $title);
     $fullpath = $dir . '/' . $title;
     if (file_exists($fullpath)) {
         // check if expired
         if ((time() - filemtime($fullpath)) > ModUtil::getVar('Theme', 'render_lifetime')) {
             return false;
         }
     } else {
         return false;
     }
     return $fullpath;
 }
コード例 #4
0
ファイル: Plugin.php プロジェクト: rmaiwald/core
 /**
  * Setup or restore storage directory.
  *
  * @param string $dir Storage directory (inside Zikula "ztemp" dir)
  *
  * @return bool
  */
 public function setupThumbDir($dir = null)
 {
     if (is_null($dir)) {
         $dir = $this->getVar('thumb_dir');
     }
     if (!($result = file_exists(CacheUtil::getLocalDir($dir)))) {
         $result = CacheUtil::createLocalDir($dir);
     }
     if ($result) {
         $dir = CacheUtil::getLocalDir($dir);
         $htaccess = "{$dir}/.htaccess";
         if (!file_exists($htaccess)) {
             $template = "{$this->getBaseDir()}/templates/default.htaccess";
             $result = copy($template, $htaccess);
         }
     }
     return $result;
 }
コード例 #5
0
 /**
  * @Route("/download/{slug}.zip", requirements={"slug"=".+"})
  * @ParamConverter("entity", class="Cmfcmf\Module\MediaModule\Entity\Collection\CollectionEntity", options={"slug" = "slug"})
  *
  * @param Request          $request
  * @param CollectionEntity $entity
  *
  * @return array
  */
 public function downloadAction(CollectionEntity $entity)
 {
     if (!$this->get('cmfcmf_media_module.security_manager')->hasPermission($entity, 'download')) {
         throw new AccessDeniedException();
     }
     \CacheUtil::createLocalDir('CmfcmfMediaModule');
     $dir = \CacheUtil::getLocalDir('CmfcmfMediaModule');
     $path = $dir . '/' . uniqid(time(), true) . '.zip';
     $zip = new \ZipArchive();
     if ($zip->open($path, \ZipArchive::CREATE) !== true) {
         throw new ServiceUnavailableHttpException('Could not create zip archive!');
     }
     $mediaTypeCollection = $this->get('cmfcmf_media_module.media_type_collection');
     $hasContent = false;
     $usedFileNames = [];
     foreach ($entity->getMedia() as $media) {
         if ($media instanceof AbstractFileEntity && $media->isDownloadAllowed()) {
             /** @var UploadableMediaTypeInterface $mediaType */
             $mediaType = $mediaTypeCollection->getMediaTypeFromEntity($media);
             $filename = $media->getBeautifiedFileName();
             $originalFileExtension = pathinfo($filename, PATHINFO_EXTENSION);
             $originalFilename = pathinfo($filename, PATHINFO_BASENAME);
             for ($i = 1; in_array($filename, $usedFileNames, true); ++$i) {
                 $filename = "{$originalFilename} ({$i})" . (empty($originalFileExtension) ?: ".{$originalFileExtension}");
             }
             $zip->addFile($mediaType->getOriginalWithWatermark($media, 'path', false), $filename);
             $hasContent = true;
         }
     }
     if (!$hasContent) {
         $zip->addFromString('Empty Collection.txt', $this->__('Sorry, the collection appears to be empty or does not have any downloadable files.'));
     }
     $zip->close();
     $response = new BinaryFileResponse($path);
     $response->deleteFileAfterSend(true);
     return $response;
 }
コード例 #6
0
ファイル: Plugin.php プロジェクト: projectesIF/Sirius
    /**
     * Initialise.
     *
     * Runs at plugin init time.
     *
     * @return void
     */
    public function initialize()
    {
        // register namespace
        // Because the standard kernel classloader already has Doctrine registered as a namespace
        // we have to add a new loader onto the spl stack.
        $autoloader = new Zikula_KernelClassLoader();
        $autoloader->spl_autoload_register();
        include 'lib/DoctrineHelper.php';
        $autoloader->register('Doctrine', dirname(__FILE__) . '/lib/vendor', '\\');
        $autoloader->register('DoctrineProxy', 'ztemp/doctrinemodels', '\\');

        $serviceManager = $this->eventManager->getServiceManager();
        $config = $GLOBALS['ZConfig']['DBInfo']['databases']['default'];
        $dbConfig = array('host' => $config['host'],
                          'user' => $config['user'],
                          'password' => $config['password'],
                          'dbname' => $config['dbname'],
                          'driver' => 'pdo_' . $config['dbdriver'],
                          );
        $r = new \ReflectionClass('Doctrine\Common\Cache\\' . $serviceManager['dbcache.type'] . 'Cache');
        $dbCache = $r->newInstance();
        $ORMConfig = new \Doctrine\ORM\Configuration;
        $serviceManager->attachService('doctrine.configuration', $ORMConfig);
        $ORMConfig->setMetadataCacheImpl($dbCache);

        // create proxy cache dir
        CacheUtil::createLocalDir('doctrinemodels');

        // setup annotations base
        include_once 'lib/vendor/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php';

        // setup annotation reader
        $reader = new \Doctrine\Common\Annotations\AnnotationReader();
        $cacheReader = new \Doctrine\Common\Annotations\CachedReader($reader, new \Doctrine\Common\Cache\ArrayCache());
        $serviceManager->attachService('doctrine.annotationreader', $cacheReader);

        // setup annotation driver
        $annotationDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($cacheReader);
        $serviceManager->attachService('doctrine.annotationdriver', $annotationDriver);

        // setup driver chains
        $driverChain = new \Doctrine\ORM\Mapping\Driver\DriverChain();
        $serviceManager->attachService('doctrine.driverchain', $driverChain);

        // configure Doctrine ORM
        $ORMConfig->setMetadataDriverImpl($annotationDriver);
        $ORMConfig->setQueryCacheImpl($dbCache);
        $ORMConfig->setProxyDir(CacheUtil::getLocalDir('doctrinemodels'));
        $ORMConfig->setProxyNamespace('DoctrineProxy');
        //$ORMConfig->setAutoGenerateProxyClasses(System::isDevelopmentMode());

        if (isset($serviceManager['log.enabled']) && $serviceManager['log.enabled']) {
            $ORMConfig->setSQLLogger(new SystemPlugin_Doctrine_ZikulaSqlLogger());
        }

        // setup doctrine eventmanager
        $eventManager = new \Doctrine\Common\EventManager;
        $serviceManager->attachService('doctrine.eventmanager', $eventManager);

         // setup MySQL specific listener (storage engine and encoding)
        if ($config['dbdriver'] == 'mysql') {
            $mysqlSessionInit = new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit($config['charset']);
            $eventManager->addEventSubscriber($mysqlSessionInit);

            $mysqlStorageEvent = new SystemPlugin_Doctrine_MySqlGenerateSchemaListener($eventManager);
        }

        // setup the doctrine entitymanager
        $entityManager = \Doctrine\ORM\EntityManager::create($dbConfig, $ORMConfig, $eventManager);
        $serviceManager->attachService('doctrine.entitymanager', $entityManager);
    }
コード例 #7
0
ファイル: Installer.php プロジェクト: projectesIF/Sirius
    /**
     * upgrade the Feeds module from an old version
     * This function can be called multiple times
     */
    public function upgrade($oldversion)
    {
        $dom = ZLanguage::getModuleDomain('Feeds');

        // when upgrading let's clear the cache directory
        CacheUtil::clearLocalDir('feeds');

        switch ($oldversion)
        {
            // version 1.0 shipped with PN .7x
            case '1.0':
            // rename table if upgrading from an earlier version
                if (in_array(DBUtil::getLimitedTablename('RSS'), DBUtil::MetaTables())) {
                    DBUtil::renameTable('RSS', 'feeds');
                }
                if (in_array(DBUtil::getLimitedTablename('rss'), DBUtil::MetaTables())) {
                    DBUtil::renameTable('rss', 'feeds');
                }

                // create cache directory
                CacheUtil::createLocalDir('feeds');

                // migrate module vars
                $tables = DBUtil::getTables();
                $sql    = "UPDATE $tables[module_vars] SET pn_modname = 'Feeds' WHERE pn_modname = 'RSS'";
                if (!DBUtil::executeSQL($sql)) {
                    LogUtil::registerError(__('Error! Update attempt failed.', $dom));
                    return '1.0';
                }

                // create our default category
                $this->setVar('enablecategorization', true);
                if (!$this->_feeds_createdefaultcategory()) {
                    LogUtil::registerError(__('Error! Update attempt failed.', $dom));
                    return '1.0';
                }

                // update table
                if (!DBUtil::changeTable('feeds')) {
                    return '1.0';
                }

                // update the permalinks
                $shorturlsep = System::getVar('shorturlsseparator');
                $sql  = "UPDATE $tables[feeds] SET pn_urltitle = REPLACE(pn_name, ' ', '{$shorturlsep}')";
                if (!DBUtil::executeSQL($sql)) {
                    LogUtil::registerError(__('Error! Update attempt failed.', $dom));
                    return '1.0';
                }

            case '2.1':
                $modvars = array('multifeedlimit' => 0,
                        'feedsperpage' => 10,
                        'usingcronjob' => 0,
                        'key' => md5(time()));

                if (!ModUtil::setVars('Feeds', $modvars)) {
                    LogUtil::registerError(__('Error! Update attempt failed.', $dom));
                    return '2.1';
                }

            // 2.2 -> 2.3 is the Gettext change
            case '2.2':
            case '2.3':
            case '2.4':
            case '2.5':
                $prefix = $this->serviceManager['prefix'];
                $connection = Doctrine_Manager::getInstance()->getConnection('default');
                $sqlStatements = array();
                // N.B. statements generated with PHPMyAdmin
                $sqlStatements[] = 'RENAME TABLE ' . $prefix . '_feeds' . " TO `feeds`";
                $sqlStatements[] = "ALTER TABLE `feeds` 
CHANGE `pn_fid` `fid` INT( 10 ) NOT NULL AUTO_INCREMENT ,
CHANGE `pn_name` `name` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',
CHANGE `pn_urltitle` `urltitle` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',
CHANGE `pn_url` `url` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',
CHANGE `pn_obj_status` `obj_status` CHAR( 1 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'A',
CHANGE `pn_cr_date` `cr_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00',
CHANGE `pn_cr_uid` `cr_uid` INT( 11 ) NOT NULL DEFAULT '0',
CHANGE `pn_lu_date` `lu_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00',
CHANGE `pn_lu_uid` `lu_uid` INT( 11 ) NOT NULL DEFAULT '0'";
                foreach ($sqlStatements as $sql) {
                    $stmt = $connection->prepare($sql);
                    try {
                        $stmt->execute();
                    } catch (Exception $e) {
                    }   
                }
            case '2.6.0':
                $this->delVar('feedsperpage');
            case '2.6.1':
            // further upgrade routine
        }

        // update successful
        return true;
    }