getTableColumns() public static method

Get list of installed columns in a table
public static getTableColumns ( string $tableName ) : array
$tableName string The name of a table.
return array Installed columns indexed by the column name.
 /**
  * @expectedException \Zend_Db_Statement_Exception
  * @expectedExceptionMessage custom_dimensions
  */
 public function test_shouldBeAbleToUninstallConfigTable()
 {
     $this->config->uninstall();
     try {
         DbHelper::getTableColumns($this->tableName);
         // doesn't work anymore as table was removed
     } catch (Zend_Db_Statement_Exception $e) {
         $this->config->install();
         throw $e;
     }
     $this->config->install();
 }
示例#2
0
 public static function getAllVersions()
 {
     // to avoid having to load all dimensions on each request we check if there were any changes on the file system
     // can easily save > 100ms for each request
     $cachedTimes = self::getCachedDimensionFileChanges();
     $currentTimes = self::getCurrentDimensionFileChanges();
     $diff = array_diff_assoc($currentTimes, $cachedTimes);
     if (empty($diff)) {
         return array();
     }
     $versions = array();
     $visitColumns = DbHelper::getTableColumns(Common::prefixTable('log_visit'));
     $actionColumns = DbHelper::getTableColumns(Common::prefixTable('log_link_visit_action'));
     $conversionColumns = DbHelper::getTableColumns(Common::prefixTable('log_conversion'));
     foreach (self::getVisitDimensions() as $dimension) {
         $versions = self::mixinVersions($dimension, 'log_visit.', $visitColumns, $versions);
     }
     foreach (self::getActionDimensions() as $dimension) {
         $versions = self::mixinVersions($dimension, 'log_link_visit_action.', $actionColumns, $versions);
     }
     foreach (self::getConversionDimensions() as $dimension) {
         $versions = self::mixinVersions($dimension, 'log_conversion.', $conversionColumns, $versions);
     }
     return $versions;
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param string $type
  * @return array
  * @throws \RuntimeException
  */
 protected function getColumnName(InputInterface $input, OutputInterface $output, $type)
 {
     $validate = function ($columnName) use($type) {
         if (empty($columnName)) {
             throw new \InvalidArgumentException('Please enter the name of the dimension column');
         }
         if (preg_match("/[^A-Za-z0-9_ ]/", $columnName)) {
             throw new \InvalidArgumentException('Only alpha numerical characters, underscores and whitespaces are allowed');
         }
         if ('visit' == $type) {
             $columns = array_keys(DbHelper::getTableColumns(Common::prefixTable('log_visit')));
         } elseif ('action' == $type) {
             $columns = array_keys(DbHelper::getTableColumns(Common::prefixTable('log_link_visit_action')));
         } elseif ('conversion' == $type) {
             $columns = array_keys(DbHelper::getTableColumns(Common::prefixTable('log_conversion')));
         } else {
             $columns = array();
         }
         foreach ($columns as $column) {
             if (strtolower($column) === strtolower($columnName)) {
                 throw new \InvalidArgumentException('This column name is already in use.');
             }
         }
         return $columnName;
     };
     $columnName = $input->getOption('columnname');
     if (empty($columnName)) {
         $dialog = $this->getHelperSet()->get('dialog');
         $columnName = $dialog->askAndValidate($output, 'Enter the name of the column under which it should be stored in the MySQL database, for instance "visit_total_time": ', $validate);
     } else {
         $validate($columnName);
     }
     return $columnName;
 }
示例#4
0
文件: 2.14.2.php 项目: piwik/piwik
 /**
  * @param string $tableName
  * @return array  An array of actually existing column names in the given table. eg array('idvist', 'server_time', ...)
  */
 private static function getActuallyExistingColumns($tableName)
 {
     $tableName = Common::prefixTable($tableName);
     return array_keys(DbHelper::getTableColumns($tableName));
 }
 public function test_uninstall_shouldInstallColumn_LogVisit_LastIdlinkVa()
 {
     $this->logVisit->uninstall();
     $columnn = DbHelper::getTableColumns(Common::prefixTable('log_visit'));
     $this->assertArrayNotHasKey('last_idlink_va', $columnn);
 }
示例#6
0
 public function getAllVersions(PiwikUpdater $updater)
 {
     // to avoid having to load all dimensions on each request we check if there were any changes on the file system
     // can easily save > 100ms for each request
     $cachedTimes = self::getCachedDimensionFileChanges();
     $currentTimes = self::getCurrentDimensionFileChanges();
     $diff = array_diff_assoc($currentTimes, $cachedTimes);
     if (empty($diff)) {
         return array();
     }
     $versions = array();
     $visitColumns = DbHelper::getTableColumns(Common::prefixTable('log_visit'));
     $actionColumns = DbHelper::getTableColumns(Common::prefixTable('log_link_visit_action'));
     $conversionColumns = DbHelper::getTableColumns(Common::prefixTable('log_conversion'));
     foreach ($this->visitDimensions as $dimension) {
         $versions = $this->mixinVersions($updater, $dimension, VisitDimension::INSTALLER_PREFIX, $visitColumns, $versions);
     }
     foreach ($this->actionDimensions as $dimension) {
         $versions = $this->mixinVersions($updater, $dimension, ActionDimension::INSTALLER_PREFIX, $actionColumns, $versions);
     }
     foreach ($this->conversionDimensions as $dimension) {
         $versions = $this->mixinVersions($updater, $dimension, ConversionDimension::INSTALLER_PREFIX, $conversionColumns, $versions);
     }
     return $versions;
 }
 private function hasColumn($field)
 {
     $columns = DbHelper::getTableColumns($this->table);
     return array_key_exists($field, $columns);
 }