示例#1
0
文件: CMS.php 项目: samsonos/cms_api
 /**
  * @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();
 }
示例#2
0
文件: CMS.php 项目: samsoncms/api
    /**
     * @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();
    }