Пример #1
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 . ']');
                foreach ($this->readSQL($path . $file, $this->tablePrefix) as $sql) {
                    $this->database->execute($sql);
                }
            }
            $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
        m('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();
    }