Пример #1
0
 public function testRenameField()
 {
     $o = new Db_Object_Builder('Page');
     $cfg = Db_Object_Config::getInstance('Page');
     $this->assertTrue($cfg->renameField('page_title', 'untitle'));
     $this->assertTrue($o->validate());
     $this->assertTrue($cfg->renameField('untitle', 'page_title'));
     $this->assertTrue($o->validate());
 }
Пример #2
0
 public function testValidate()
 {
     $o = new Db_Object_Builder('Page');
     $o->build();
     $this->assertTrue($o->validate());
 }
Пример #3
0
 public static function getDbStats()
 {
     $data = array();
     /*
      * Getting list of objects
      */
     $manager = new Db_Object_Manager();
     $externalExpert = $manager->getExternalsExpert();
     $names = $manager->getRegisteredObjects();
     if (empty($names)) {
         return array();
     }
     $tables = array();
     /*
      * forming result set
      */
     foreach ($names as $objectName) {
         $configObject = Db_Object_Config::getInstance($objectName);
         $objectModel = Model::factory($objectName);
         $config = $configObject->__toArray();
         $objectTable = $objectModel->table();
         $builder = new Db_Object_Builder($objectName);
         $records = 0;
         $dataLength = 0;
         $indexLength = 0;
         $size = 0;
         $oModel = Model::factory($objectName);
         $oDb = $oModel->getDbConnection();
         $oDbConfig = $oDb->getConfig();
         $oDbHash = md5(serialize($oDbConfig));
         $canConnect = true;
         if (!isset($tables[$oDbHash])) {
             try {
                 /*
                  * Getting object db tables info
                  */
                 $tablesData = $oDb->fetchAll("SHOW TABLE STATUS");
             } catch (Exception $e) {
                 $canConnect = false;
             }
             if (!empty($tablesData)) {
                 foreach ($tablesData as $k => $v) {
                     $tables[$oDbHash][$v['Name']] = array('rows' => $v['Rows'], 'data_length' => $v['Data_length'], 'index_length' => $v['Index_length']);
                 }
             }
             unset($tablesData);
         }
         if (Registry::get('main', 'config')->get('orm_innodb_real_rows_count') && strtolower($config['engine']) === 'innodb' && $builder->tableExists($oModel->table())) {
             /*
              * Real rows count for innodb tables
              */
             $tables[$oDbHash][$objectTable]['rows'] = $oModel->getCount();
         }
         if (isset($tables[$oDbHash][$objectTable])) {
             $records = $tables[$oDbHash][$objectTable]['rows'];
             $dataLength = Utils::formatFileSize($tables[$oDbHash][$objectTable]['data_length']);
             $indexLength = Utils::formatFileSize($tables[$oDbHash][$objectTable]['index_length']);
             $size = Utils::formatFileSize($tables[$oDbHash][$objectTable]['data_length'] + $tables[$oDbHash][$objectTable]['index_length']);
         }
         $title = '';
         $saveHistory = true;
         $linktitle = '';
         if (isset($config['title']) && !empty($config['title'])) {
             $title = $config['title'];
         }
         if (isset($config['link_title']) && !empty($config['link_title'])) {
             $linktitle = $config['link_title'];
         }
         if (isset($config['save_history']) && !$config['save_history']) {
             $saveHistory = false;
         }
         $external = false;
         if ($externalExpert && $externalExpert->hasObject($objectName)) {
             $external = true;
         }
         $hasBroken = false;
         if ($builder->hasBrokenLinks()) {
             $hasBroken = true;
         }
         $data[] = array('name' => $objectName, 'table' => $objectTable, 'engine' => $config['engine'], 'vc' => $config['rev_control'], 'fields' => sizeof($config['fields']), 'records' => number_format($records, 0, '.', ' '), 'title' => $title, 'link_title' => $linktitle, 'rev_control' => $config['rev_control'], 'save_history' => $saveHistory, 'data_size' => $dataLength, 'index_size' => $indexLength, 'size' => $size, 'system' => $configObject->isSystem(), 'external' => $external, 'validdb' => $builder->validate(), 'broken' => $hasBroken, 'db_host' => $oDbConfig['host'], 'db_name' => $oDbConfig['dbname'], 'locked' => $config['locked'], 'readonly' => $config['readonly'], 'can_connect' => $canConnect, 'primary_key' => $configObject->getPrimaryKey(), 'connection' => $config['connection']);
     }
     return $data;
 }