/** * Добавление поля node.xml2 для хранения дерева. * @mcms_message ru.molinos.cms.install */ public static function on_install(Context $ctx) { $t = new TableInfo($ctx->db, 'node'); if (!$t->columnExists('xmltree')) { $t->columnSet('xmltree', array('type' => 'longblob')); $t->commit(); } }
public static function rpc_rebuild(Context $ctx) { // Обновление БД. foreach (os::find('lib/modules/*/*.yml') as $fileName) { $schema = Spyc::YAMLLoad($fileName); Logger::log('applying ' . $fileName, 'module'); if (!empty($schema['tables'])) { foreach ($schema['tables'] as $tableName => $tableInfo) { TableInfo::check($tableName, $tableInfo); } } } $ctx->registry->rebuild(); $ctx->registry->broadcast('ru.molinos.cms.install', array($ctx)); }
/** * Создание всех индексов, описанных в типе. */ private static function recreateIndexes(Context $ctx, Node $type) { $tran = $ctx->db->isTransactionRunning(); foreach ((array) $type->fields as $name => $info) { if (!Node::isBasicField($name) and !empty($info['indexed'])) { if ($sql = Control::getIndexType($info['type'])) { try { TableInfo::check('node__idx_' . $name, array('id' => array('type' => 'integer', 'required' => true, 'key' => 'pri'), 'value' => array('type' => $sql, 'required' => false, 'key' => 'mul'))); } catch (PDOException $e) { Logger::log("error reindexing {$info['type']}.{$name}: " . $e->getMessage()); } } } } if ($tran) { $ctx->db->beginTransaction(); } }
/** * @param string $table The table name. * @param string $database The database name. * @param resource $dblink The db connection resource. */ function __construct(DatabaseInfo $database, $name, $version, $intOID) { parent::__construct($database, $name); $this->version = $version; $this->oid = $intOID; }
/** * Adds a table to this db. * Table name is case-insensitive. * @param TableInfo $table */ public function addTable(TableInfo $table) { $this->tables[strtoupper($table->getName())] = $table; }
public function testInternalTables() { $tables = array('node', 'node__access', 'node__rel'); $ctx = get_test_context(); foreach ($tables as $table) { $c = $ctx->db->fetch("SELECT COUNT(*) FROM `{$table}`"); $t = new TableInfo($ctx->db, $table); $this->assertTrue($t->exists()); } }
public function __construct(OCI8DatabaseInfo $database, $name) { $this->schema = strtoupper($database->getSchema()); parent::__construct($database, $name); $this->name = strtoupper($this->name); }
/** * Проверяет структуру таблицы. */ public static function check($tableName, array $columns) { Logger::log("checking({$tableName}): " . implode(', ', array_keys($columns)) . '.'); $t = new TableInfo(Context::last()->db, $tableName); foreach ($columns as $k => $v) { // FIXME: на переходном этапе конвертируем структуру, вообще надо её понимать сразу правильно. switch ($v['type']) { case 'decimal': $v['type'] = $v['type'] . '(' . $v['length'] . ',' . $v['precision']; break; case 'bool': $v['type'] = 'tinyint(1)'; break; case 'char': case 'varchar': $v['type'] = $v['type'] . '(' . $v['length'] . ')'; break; case 'text': $v['type'] = 'mediumtext'; break; case 'blob': $v['type'] = 'mediumblob'; break; } if (!empty($v['primary'])) { $v['key'] = 'pri'; } elseif (!empty($v['indexed'])) { $v['key'] = 'mul'; } $t->columnSet($k, $v); } $t->commit(); }