Exemple #1
0
 /**
  * Module initialization.
  *
  * @param array $params Initialization parameters collection
  * @return bool Initialization result
  */
 public function init(array $params = array())
 {
     //[PHPCOMPRESSOR(remove,start)]
     // Create SamsonPHP routing table from loaded modules
     $rg = new GenericRouteGenerator($this->system->module_stack);
     // Generate web-application routes
     $routes = $rg->generate();
     $routes->add($this->findGenericDefaultAction());
     // Create cache marker
     $this->cacheFile = $routes->hash() . '.php';
     // If we need to refresh cache
     if ($this->cache_refresh($this->cacheFile)) {
         $generator = new Structure($routes, new \samsonphp\generator\Generator());
         // Generate routing logic function
         $routerLogic = $generator->generate();
         // Store router logic in cache
         file_put_contents($this->cacheFile, '<?php ' . "\n" . $routerLogic);
     }
     require $this->cacheFile;
     //[PHPCOMPRESSOR(remove,end)]
     // This should be change to receive path as a parameter on initialization
     $pathParts = explode(Route::DELIMITER, $_SERVER['REQUEST_URI']);
     SamsonLocale::parseURL($pathParts);
     $this->requestURI = implode(Route::DELIMITER, $pathParts);
     // Subscribe to samsonphp\core routing event
     \samsonphp\event\Event::subscribe('core.routing', array($this, 'router'));
     // Continue initialization
     return parent::init($params);
 }
 /**
  * Module initialization
  * @param array $params Collection of parameters
  * @return bool|void
  */
 public function init(array $params = array())
 {
     // Store pointer to file system module
     $this->fs =& m('fs');
     // Call parent initialization
     parent::init($params);
 }
Exemple #3
0
 /**
  * Application constructor.
  *
  * @param string $path
  * @param ResourcesInterface $resources
  * @param SystemInterface $system
  */
 public function __construct($path, ResourcesInterface $resources, SystemInterface $system)
 {
     // Inject dependencies
     $this->social = m('socialemail');
     $this->request = url();
     $this->query = new dbQuery();
     parent::__construct($path, $resources, $system);
 }
 /**
  * Initialize module
  * @param array $params Collection of module parameters
  * @return bool True if module successfully initialized
  */
 public function init(array $params = array())
 {
     // Init FileSystem and ServerHandler
     $this->initFileSystem();
     // If no valid handlers are passed - use generic handlers
     if (!isset($this->uploadDirHandler) || !is_callable($this->uploadDirHandler)) {
         $this->uploadDirHandler = array($this, 'defaultDirHandler');
     }
     // Call parent initialization
     parent::init($params);
 }
Exemple #5
0
 public function init(array $params = array())
 {
     //trace('cmsInit');
     // Old applications main page rendering
     Event::subscribe('template.main.rendered', array($this, 'oldMainRenderer'));
     // Old applications menu rendering
     Event::subscribe('template.menu.rendered', array($this, 'oldMenuRenderer'));
     Event::subscribe('samson.url.build', array($this, 'buildUrl'));
     Event::subscribe('samson.url.args.created', array($this, 'parseUrl'));
     Event::subscribe(Module::EVENT_ROUTE_FOUND, array($this, 'activeModuleHandler'));
     Event::subscribe('samsonphp.router.create.module.routes', array($this, 'updateCMSPrefix'));
     //[PHPCOMPRESSOR(remove,start)]
     $moduleList = $this->system->module_stack;
     foreach ($this->system->module_stack as $id => $module) {
         if (!$this->isModuleDependent($module) && $id != 'core' && !$this->ifModuleRelated($module)) {
             unset($moduleList[$id]);
         }
     }
     // Generate resources for new module
     $this->system->module('resourcer')->generateResources($moduleList, $this->path() . 'app/view/index.php');
     //[PHPCOMPRESSOR(remove,end)]
     // Call parent initialization
     return parent::init($params);
 }
Exemple #6
0
 /**
  * @see ModuleConnector::prepare()
  */
 public function oldprepare()
 {
     // SQL команда на добавление таблицы пользователей
     $sql_user = "******" . dbMySQLConnector::$prefix . "user` (\n              `UserID` int(11) NOT NULL AUTO_INCREMENT,\n\t\t  `FName` varchar(255) NOT NULL,\n\t\t  `SName` varchar(255) NOT NULL,\n\t\t  `TName` varchar(255) NOT NULL,\n\t\t  `Email` varchar(255) NOT NULL,\n\t\t  `Password` varchar(255) NOT NULL,\n\t\t  `md5_email` varchar(255) NOT NULL,\n\t\t  `md5_password` varchar(255) NOT NULL,\n\t\t  `Created` datetime NOT NULL,\n\t\t  `Modyfied` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t  `GroupID` int(11) NOT NULL,\n\t\t  `Active` int(11) NOT NULL,\n\t\t  `Online` int(11) NOT NULL,\n\t\t  `LastLogin` datetime NOT NULL,\n\t\t  PRIMARY KEY (`UserID`)\n\t\t) ENGINE=INNODB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;";
     // SQL команда на добавление таблицы пользователей
     $sql_gallery = "CREATE TABLE IF NOT EXISTS `" . dbMySQLConnector::$prefix . "gallery` (\n\t\t  `PhotoID` int(11) NOT NULL AUTO_INCREMENT,\n\t\t  `MaterialID` int(11) NOT NULL,\n\t\t  `Path` varchar(255) NOT NULL,\n\t\t  `Src` varchar(255) NOT NULL,\n\t\t  `Loaded` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t  `Description` text NOT NULL,\n\t\t  `Name` varchar(255) NOT NULL,\n\t\t  `Active` int(11) NOT NULL,\n\t\t  PRIMARY KEY (`PhotoID`)\n\t\t) ENGINE=INNODB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;";
     // SQL команда на добавление таблицы групп пользователей
     $sql_group = "CREATE TABLE IF NOT EXISTS `" . dbMySQLConnector::$prefix . "group` (\n\t\t  `GroupID` int(20) NOT NULL AUTO_INCREMENT,\n\t\t  `Name` varchar(255) NOT NULL,\n\t\t  `Active` int(11) NOT NULL,\n\t\t  PRIMARY KEY (`GroupID`)\n\t\t) ENGINE=INNODB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;";
     // SQL команда на добавление таблицы связей пользователей и групп
     $sql_groupright = "CREATE TABLE IF NOT EXISTS `" . dbMySQLConnector::$prefix . "groupright` (\n\t\t  `GroupRightID` int(11) NOT NULL AUTO_INCREMENT,\n\t\t  `GroupID` int(10) NOT NULL,\n\t\t  `RightID` int(20) NOT NULL,\n\t\t  `Entity` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '_',\n\t\t  `Key` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,\n\t\t  `Ban` int(10) NOT NULL,\n\t\t  `TS` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t  `Active` int(11) NOT NULL,\n\t\t  PRIMARY KEY (`GroupRightID`)\n\t\t) ENGINE=INNODB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0;";
     // SQL команда на добавление таблицы прав пользователей
     $sql_right = "CREATE TABLE IF NOT EXISTS `" . dbMySQLConnector::$prefix . "right` (\n\t\t  `RightID` int(20) NOT NULL AUTO_INCREMENT,\n\t\t  `Name` varchar(255) NOT NULL,\n\t\t  `Description` varchar(255) NOT NULL,\n\t\t  `Active` int(11) NOT NULL,\n\t\t  PRIMARY KEY (`RightID`)\n\t\t) ENGINE=INNODB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;";
     // Related materials
     $sql_relation_material = "CREATE TABLE IF NOT EXISTS `" . dbMySQLConnector::$prefix . "related_materials` (\n\t\t  `related_materials_id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t  `first_material` int(11) NOT NULL,\n\t\t  `first_locale` varchar(10) NOT NULL,\n\t\t  `second_material` int(11) NOT NULL,\n\t\t  `second_locale` varchar(10) NOT NULL,\n\t\t  PRIMARY KEY (`related_materials_id`)\n\t\t) ENGINE=INNODB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;";
     // SQL команда на добавление таблицы материалов
     $sql_material = "CREATE TABLE IF NOT EXISTS `" . dbMySQLConnector::$prefix . "material` (\n\t\t  `MaterialID` int(11) NOT NULL AUTO_INCREMENT,\n\t\t  `Name` varchar(555) NOT NULL,\n\t\t  `Content` text NOT NULL,\n\t\t  `Published` int(11) NOT NULL,\n\t\t  `Created` datetime NOT NULL,\n\t\t  `UserID` int(11) NOT NULL,\n\t\t  `Modyfied` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t  `Teaser` text NOT NULL,\n\t\t  `Url` varchar(255) NOT NULL,\n\t\t  `Keywords` varchar(255) NOT NULL,\n\t\t  `Description` varchar(255) NOT NULL,\n\t\t  `Title` varchar(255) NOT NULL,\n\t\t  `Draft` int(11) NOT NULL,\n\t\t  `Draftmaterial` int(11) NOT NULL,\n\t\t  `Active` int(11) NOT NULL DEFAULT '1',\n\t\t  `structure_id` int(11) NOT NULL,\n\t\tPRIMARY KEY (`MaterialID`),\n\t\tKEY `Url` (`Url`)\n\t\t) ENGINE=INNODB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;";
     // SQL команда на добавление таблицы навигации
     $sql_structure = "CREATE TABLE IF NOT EXISTS `" . dbMySQLConnector::$prefix . "structure` (\n\t\t  `StructureID` int(11) NOT NULL AUTO_INCREMENT,\n\t\t  `ParentID` int(11) NOT NULL,\n\t\t  `Name` varchar(255) NOT NULL,\n\t\t  `Created` datetime NOT NULL,\n\t\t  `UserID` int(11) NOT NULL,\n\t\t  `Modyfied` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t  `Url` varchar(255) NOT NULL,\n\t\t  `MaterialID` int(11) NOT NULL,\n\t\t  `PriorityNumber` int(11) NOT NULL,\n\t\t  `Active` int(11) NOT NULL DEFAULT '1',\n\t\tPRIMARY KEY (`StructureID`),\n\t\tKEY `Url` (`Url`)\n\t\t) ENGINE=INNODB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;";
     // SQL комманда на создание таблицы связей навигации и материалов
     $sql_structurematerial = "CREATE TABLE IF NOT EXISTS `" . dbMySQLConnector::$prefix . "structurematerial` (\n\t\t  `StructureMaterialID` int(11) NOT NULL AUTO_INCREMENT,\n\t\t  `StructureID` int(11) NOT NULL,\n\t\t  `MaterialID` int(11) NOT NULL,\n\t\t  `Modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t  `Active` int(11) NOT NULL DEFAULT '1',\n\t\t  PRIMARY KEY (`StructureMaterialID`),\n\t\t  KEY `StructureID` (`StructureID`),\n\t\t  KEY `MaterialID` (`MaterialID`)\n\t\t) ENGINE=INNODB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;";
     // SQL команда на добавление таблицы полей
     $sql_field = "CREATE TABLE IF NOT EXISTS `" . dbMySQLConnector::$prefix . "field` (\n\t\t  `FieldID` int(11) NOT NULL AUTO_INCREMENT,\n\t\t  `ParentID` int(11) NOT NULL,\n\t\t  `Name` varchar(255) NOT NULL,\n\t\t  `Type` int(11) NOT NULL,\n\t\t  `Value` text NOT NULL,\n\t\t  `Description` text NOT NULL,\n\t\t  `UserID` int(11) NOT NULL,\n\t\t  `Created` datetime NOT NULL,\n\t\t  `Modyfied` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t  `Active` int(11) NOT NULL,\n\t\t  PRIMARY KEY (`FieldID`)\n\t\t) ENGINE=INNODB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;";
     // SQL команда на добавление таблицы связей ЄНС с полями
     $sql_navfield = "CREATE TABLE IF NOT EXISTS `" . dbMySQLConnector::$prefix . "structurefield` (\n\t\t  `StructureFieldID` int(11) NOT NULL AUTO_INCREMENT,\n\t\t  `StructureID` int(11) NOT NULL,\n\t\t  `FieldID` int(11) NOT NULL,\n\t\t  `Modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t  `Active` int(11) NOT NULL,\n\t\t  PRIMARY KEY (`StructureFieldID`),\n\t\t  KEY `StructureID` (`StructureID`)\n\t\t) ENGINE=INNODB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;";
     // SQL комманда на создание таблицы связей материалов и полей
     $sql_materialfield = "CREATE TABLE IF NOT EXISTS `" . dbMySQLConnector::$prefix . "materialfield` (\n\t\t  `MaterialFieldID` int(11) NOT NULL AUTO_INCREMENT,\n\t\t  `FieldID` int(11) NOT NULL,\n\t\t  `MaterialID` int(11) NOT NULL,\n\t\t  `Value` text NOT NULL,\n\t\t  `Active` int(11) NOT NULL,\n\t\t  PRIMARY KEY (`MaterialFieldID`),\n\t\t  KEY `MaterialID` (`MaterialID`)\n\t\t) ENGINE=INNODB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;";
     // SQL комманда на создание таблицы связей между структурами
     $sql_structure_relation = "CREATE TABLE IF NOT EXISTS `" . dbMySQLConnector::$prefix . "structure_relation` (\n\t\t  `structure_relation_id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t  `parent_id` int(11) NOT NULL,\n\t\t  `child_id` int(11) NOT NULL,\n\t\t  PRIMARY KEY (`structure_relation_id`)\n\t\t) ENGINE=INNODB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;";
     // SQL table for storing database version
     $sql_version = " CREATE TABLE IF NOT EXISTS `" . dbMySQLConnector::$prefix . "cms_version` ( `version` varchar(15) not null default '1')\n\t\t\t\tENGINE=INNODB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;";
     // Выполним SQL комманды
     db()->query($sql_version);
     db()->query($sql_field);
     db()->query($sql_navfield);
     db()->query($sql_materialfield);
     db()->query($sql_material);
     db()->query($sql_structure);
     db()->query($sql_structurematerial);
     db()->query($sql_user);
     db()->query($sql_group);
     db()->query($sql_right);
     db()->query($sql_groupright);
     db()->query($sql_relation_material);
     db()->query($sql_gallery);
     db()->query($sql_structure_relation);
     // Initiate migration mechanism
     db()->migration(get_class($this), array($this, 'migrator'));
     // Define permanent table relations
     new TableRelation('material', 'user', 'UserID', 0, 'user_id');
     new TableRelation('material', 'gallery', 'MaterialID', TableRelation::T_ONE_TO_MANY);
     new TableRelation('material', 'materialfield', 'MaterialID', TableRelation::T_ONE_TO_MANY);
     new TableRelation('material', 'field', 'materialfield.FieldID', TableRelation::T_ONE_TO_MANY);
     new TableRelation('material', 'structurematerial', 'MaterialID', TableRelation::T_ONE_TO_MANY);
     new TableRelation('material', 'structure', 'structurematerial.StructureID', TableRelation::T_ONE_TO_MANY);
     new TableRelation('materialfield', 'field', 'FieldID');
     new TableRelation('materialfield', 'material', 'MaterialID');
     new TableRelation('structurematerial', 'structure', 'StructureID');
     new TableRelation('structurematerial', 'materialfield', 'MaterialID', TableRelation::T_ONE_TO_MANY);
     new TableRelation('structurematerial', 'material', 'MaterialID', TableRelation::T_ONE_TO_MANY);
     new TableRelation('structure', 'material', 'structurematerial.MaterialID', TableRelation::T_ONE_TO_MANY, null, 'manymaterials');
     new TableRelation('structure', 'gallery', 'structurematerial.MaterialID', TableRelation::T_ONE_TO_MANY, null, 'manymaterials');
     /*new TableRelation( 'structure', 'material', 'MaterialID' );*/
     new TableRelation('structure', 'user', 'UserID', 0, 'user_id');
     new TableRelation('structure', 'materialfield', 'material.MaterialID', TableRelation::T_ONE_TO_MANY, 'MaterialID', '_mf');
     new TableRelation('structure', 'structurematerial', 'StructureID', TableRelation::T_ONE_TO_MANY);
     new TableRelation('related_materials', 'material', 'first_material', TableRelation::T_ONE_TO_MANY, 'MaterialID');
     new TableRelation('related_materials', 'materialfield', 'first_material', TableRelation::T_ONE_TO_MANY, 'MaterialID');
     new TableRelation('field', 'structurefield', 'FieldID');
     new TableRelation('field', 'structure', 'structurefield.StructureID');
     new TableRelation('structurefield', 'field', 'FieldID');
     new TableRelation('structurefield', 'materialfield', 'FieldID');
     new TableRelation('structurefield', 'material', 'materialfield.MaterialID');
     new TableRelation('structure', 'structure_relation', 'StructureID', TableRelation::T_ONE_TO_MANY, 'parent_id', 'children_relations');
     new TableRelation('structure', 'structure', 'children_relations.child_id', TableRelation::T_ONE_TO_MANY, 'StructureID', 'children');
     new TableRelation('structure', 'structure_relation', 'StructureID', TableRelation::T_ONE_TO_MANY, 'child_id', 'parents_relations');
     new TableRelation('structure', 'structure', 'parents_relations.parent_id', TableRelation::T_ONE_TO_MANY, 'StructureID', 'parents');
     new TableRelation('structurematerial', 'structure_relation', 'StructureID', TableRelation::T_ONE_TO_MANY, 'parent_id');
     new TableRelation('groupright', 'right', 'RightID', TableRelation::T_ONE_TO_MANY);
     //elapsed('CMS:prepare');
     // Все прошло успешно
     return true && parent::prepare();
 }
Exemple #7
0
 /**
  * Module initialization.
  *
  * @param array $params Initialization parameters collection
  * @return bool Initialization result
  */
 public function init(array $params = array())
 {
     //[PHPCOMPRESSOR(remove,start)]
     // Create SamsonPHP routing table from loaded modules
     $rg = new GenericRouteGenerator($this->system->module_stack);
     // Generate web-application routes
     $routes = $rg->generate();
     $routes->add($this->findGenericDefaultAction());
     // Create cache marker
     $this->cacheFile = $routes->hash() . '.php';
     // If we need to refresh cache
     if ($this->cache_refresh($this->cacheFile)) {
         $generator = new Structure($routes, new \samsonphp\generator\Generator());
         // Generate routing logic function
         $routerLogic = $generator->generate();
         // Store router logic in cache
         file_put_contents($this->cacheFile, '<?php ' . "\n" . $routerLogic);
     }
     require $this->cacheFile;
     //[PHPCOMPRESSOR(remove,end)]
     // Set locale resolver mode
     SamsonLocale::$leaveDefaultLocale = $this->browserLocaleRedirect;
     // This should be change to receive path as a parameter on initialization
     $pathParts = array_values(array_filter(explode(Route::DELIMITER, $_SERVER['REQUEST_URI'])));
     // Parse URL and store locale found bug
     $localeFound = SamsonLocale::parseURL($pathParts, $this->browserLocaleRedirect);
     // Gather URL path parts with removed locale placeholder
     $this->requestURI = implode(Route::DELIMITER, $pathParts);
     // Get localization data
     $current = SamsonLocale::current();
     $default = SamsonLocale::$defaultLocale;
     // Browser agent language detection logic
     if ($this->browserLocaleRedirect && !$localeFound) {
         // Redirect to browser language
         $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
         // Is browser language supported by application
         $langSupport = in_array($lang, SamsonLocale::get(), true);
         /**
          * If browser language header is supported by our web-application and we are already not on that locale
          * and current locale is not default.
          */
         if ($current === $default && $current !== $lang && $langSupport) {
             header('Location: http://' . $_SERVER['HTTP_HOST'] . '/' . $lang . '/' . $this->requestURI);
             exit;
         } elseif (!$langSupport || $lang === $current) {
             SamsonLocale::$leaveDefaultLocale = false;
         }
     }
     // Subscribe to samsonphp\core routing event
     \samsonphp\event\Event::subscribe('core.routing', array($this, 'router'));
     // Continue initialization
     return parent::init($params);
 }
Exemple #8
0
 /** De-serialization handler */
 public function __wakeup()
 {
     parent::__wakeup();
     // Save CMSApplication instance
     if (!in_array(get_class($this), array(__CLASS__, 'samson\\cms\\App'))) {
         // Add instance to static collection
         self::$loaded[$this->id] =& $this;
     }
 }
Exemple #9
0
 /**
  * Application constructor.
  *
  * @param string $path
  * @param ResourcesInterface $resources
  * @param SystemInterface $system
  *
  * @ InjectArgument(socialEmail="samson\social\email\Email")
  * @ InjectArgument(request="samson\url\URL")
  * @ InjectArgument(queryInterface="samsonframework\orm\QueryInterface")
  *
  * @ InjectArgument(resources="samsonframework\core\ResourcesInterface")
  * @ InjectArgument(system="samsonframework\core\SystemInterface")
  */
 public function __construct($path, Email $socialEmail, URL $request, QueryInterface $queryInterface, ResourcesInterface $resources, SystemInterface $system)
 {
     parent::__construct(realpath(__DIR__ . '/../'), $resources, $system);
     // Inject dependencies
     //        $this->social = $this->system->module('socialemail');
     //        $this->request = $this->system->module('samsonos_php_url');
     //        $this->query = new dbQuery();
     $this->social = $socialEmail;
     $this->request = $request;
     $this->query = $queryInterface;
 }
Exemple #10
0
 /** @see \samson\core\ExternalModule::init() */
 public function init(array $params = array())
 {
     parent::init($params);
     // Set table prefix
     dbMySQLConnector::$prefix = $this->prefix;
     db()->connect($this->name, $this->login, $this->pwd, $this->host, $this->port);
     //[PHPCOMPRESSOR(remove,start)]
     // Generate table relations
     $this->relations();
     //[PHPCOMPRESSOR(remove,end)]
 }
Exemple #11
0
    /**
     * @see ModuleConnector::prepare()
     */
    public function prepare()
    {
        // Create cms_version
        $this->database->execute('
CREATE TABLE IF NOT EXISTS `cms_version`  (
  `version` varchar(15) NOT NULL DEFAULT \'30\'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
        // Perform this migration and execute only once
        if ($this->migrator() != 40) {
            // Perform SQL table creation
            $path = __DIR__ . '/../sql/';
            foreach (array_slice(scandir($path), 2) as $file) {
                trace('Performing database script [' . $file . ']');
                try {
                    foreach ($this->readSQL($path . $file, $this->tablePrefix) as $sql) {
                        $this->database->execute($sql);
                    }
                } catch (\Exception $e) {
                    throw new \Exception('Canot execute file: "' . $file . '"' . "\n" . $e->getMessage());
                }
            }
            $this->migrator(40);
        }
        // Initiate migration mechanism
        //        $this->database->migration(get_class($this), array($this, 'migrator'));
        // Define permanent table relations
        //        new TableRelation('material', 'user', 'UserID', 0, 'user_id');
        //        new TableRelation('material', 'gallery', 'MaterialID', TableRelation::T_ONE_TO_MANY);
        //        new TableRelation('material', 'materialfield', 'MaterialID', TableRelation::T_ONE_TO_MANY);
        //        new TableRelation('material', 'field', 'materialfield.FieldID', TableRelation::T_ONE_TO_MANY);
        //        new TableRelation('material', 'structurematerial', 'MaterialID', TableRelation::T_ONE_TO_MANY);
        //        new TableRelation('material', 'structure', 'structurematerial.StructureID', TableRelation::T_ONE_TO_MANY);
        //        new TableRelation('materialfield', 'field', 'FieldID');
        //        new TableRelation('materialfield', 'material', 'MaterialID');
        //        new TableRelation('structurematerial', 'structure', 'StructureID');
        //        new TableRelation('structurematerial', 'materialfield', 'MaterialID', TableRelation::T_ONE_TO_MANY);
        //        new TableRelation('structurematerial', 'material', 'MaterialID', TableRelation::T_ONE_TO_MANY);
        //        new TableRelation('structure', 'material', 'structurematerial.MaterialID', TableRelation::T_ONE_TO_MANY, null, 'manymaterials');
        //        new TableRelation('structure', 'gallery', 'structurematerial.MaterialID', TableRelation::T_ONE_TO_MANY, null, 'manymaterials');
        //        /*new TableRelation( 'structure', 'material', 'MaterialID' );*/
        //        new TableRelation('structure', 'user', 'UserID', 0, 'user_id');
        //        new TableRelation('structure', 'materialfield', 'material.MaterialID', TableRelation::T_ONE_TO_MANY, 'MaterialID', '_mf');
        //        new TableRelation('structure', 'structurematerial', 'StructureID', TableRelation::T_ONE_TO_MANY);
        //        //new TableRelation('related_materials', 'material', 'first_material', TableRelation::T_ONE_TO_MANY, 'MaterialID');
        //        //new TableRelation('related_materials', 'materialfield', 'first_material', TableRelation::T_ONE_TO_MANY, 'MaterialID');
        //        new TableRelation('field', 'structurefield', 'FieldID');
        //        new TableRelation('field', 'structure', 'structurefield.StructureID');
        //        new TableRelation('structurefield', 'field', 'FieldID');
        //        new TableRelation('structurefield', 'materialfield', 'FieldID');
        //        new TableRelation('structurefield', 'material', 'materialfield.MaterialID');
        //        new TableRelation('structure', 'structure_relation', 'StructureID', TableRelation::T_ONE_TO_MANY, 'parent_id', 'children_relations');
        //        new TableRelation('structure', 'structure', 'children_relations.child_id', TableRelation::T_ONE_TO_MANY, 'StructureID', 'children');
        //        new TableRelation('structure', 'structure_relation', 'StructureID', TableRelation::T_ONE_TO_MANY, 'child_id', 'parents_relations');
        //        new TableRelation('structure', 'structure', 'parents_relations.parent_id', TableRelation::T_ONE_TO_MANY, 'StructureID', 'parents');
        //        new TableRelation('structurematerial', 'structure_relation', 'StructureID', TableRelation::T_ONE_TO_MANY, 'parent_id');
        //        new TableRelation('groupright', 'right', 'RightID', TableRelation::T_ONE_TO_MANY);
        // TODO: Should be removed
        //        $this->system->module('activerecord')->relations();
        $classWriter = new GenericWriter($this->database, new Generator(), __NAMESPACE__ . '\\generated', [\samsoncms\api\generator\analyzer\RealAnalyzer::class => [\samsoncms\api\generator\RealEntity::class, \samsoncms\api\generator\RealQuery::class, \samsoncms\api\generator\RealCollection::class], \samsoncms\api\generator\analyzer\TableTraitAnalyzer::class => [\samsoncms\api\generator\TableTrait::class], \samsoncms\api\generator\analyzer\VirtualAnalyzer::class => [\samsoncms\api\generator\VirtualEntity::class, \samsoncms\api\generator\VirtualQuery::class, \samsoncms\api\generator\VirtualCollection::class], \samsoncms\api\generator\analyzer\GalleryAnalyzer::class => [\samsoncms\api\generator\Gallery::class], \samsoncms\api\generator\analyzer\TableAnalyzer::class => [\samsoncms\api\generator\TableVirtualEntity::class, \samsoncms\api\generator\TableVirtualQuery::class, \samsoncms\api\generator\TableVirtualCollection::class, \samsoncms\api\generator\Table::class, \samsoncms\api\generator\Row::class]], $this->cache_path);
        $classWriter->write();
        return parent::prepare();
    }
Exemple #12
0
 /** @see \samson\core\ExternalModule::init() */
 public function init(array $params = array())
 {
     parent::init($params);
     // Set table prefix
     dbMySQLConnector::$prefix = $this->prefix;
     //db()->connect($this->name, $this->login, $this->pwd, $this->host, $this->port);
 }