/** * Get connection for DbUnit * * @return \PHPUnit_Extensions_Database_DB_IDatabaseConnection */ public function getConnection() { if (!$this->_db) { $pdo = static::$_table->getAdapter()->getDriver()->getConnection()->getResource(); $this->_db = $this->createDefaultDBConnection($pdo, ':memory:'); } return $this->_db; }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->_hydrator = new \Zend\Stdlib\Hydrator\ArraySerializable(); $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy(array('operator' => 'OperatorCode', 'opname' => 'OperatorName', 'country' => 'CountryCode', 'serialnumber' => 'SimSerial', 'deviceid' => 'DeviceId'))); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $serviceLocator->get('Model\\Client\\Item\\Sim')); parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->_hydrator = new \Zend\Hydrator\ArraySerializable(); $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy(array('workgroup' => 'Workgroup', 'user_domain' => 'UserDomain', 'company' => 'Company', 'owner' => 'Owner', 'product_key' => 'ProductKey', 'product_id' => 'ProductId', 'manual_product_key' => 'ManualProductKey', 'cpu_architecture' => 'CpuArchitecture'))); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $serviceLocator->get('Model\\Client\\WindowsInstallation')); parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->_hydrator = new \Zend\Hydrator\ArraySerializable(); $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy(array('name' => 'Name', 'type' => 'Type'))); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $serviceLocator->get('Model\\Client\\Item\\Modem')); parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'drives'; $this->_hydrator = new \Database\Hydrator\Filesystems(); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $serviceLocator->get('Model\\Client\\Item\\Filesystem')); parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'officepack'; $this->_hydrator = new \Zend\Hydrator\ArraySerializable(); $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy(array('product' => 'Name', 'officeversion' => 'Version', 'note' => 'ExtraDescription', 'type' => 'Architecture', 'productid' => 'ProductId', 'officekey' => 'ProductKey', 'guid' => 'Guid', 'install' => 'Type'))); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $serviceLocator->get('Model\\Client\\Item\\MsOfficeProduct')); parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'cpus'; $this->_hydrator = new \Zend\Stdlib\Hydrator\ArraySerializable(); $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy(array('manufacturer' => 'Manufacturer', 'type' => 'Type', 'cores' => 'NumCores', 'cpuarch' => 'Architecture', 'data_width' => 'DataWidth', 'l2cachesize' => 'L2CacheSize', 'socket' => 'SocketType', 'speed' => 'NominalClock', 'current_speed' => 'CurrentClock', 'voltage' => 'Voltage', 'serialnumber' => 'Serial'))); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $serviceLocator->get('Model\\Client\\Item\\Cpu')); parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'sounds'; $this->_hydrator = new \Zend\Hydrator\ArraySerializable(); $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy(array('manufacturer' => 'Manufacturer', 'name' => 'Name', 'description' => 'Description'))); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $serviceLocator->get('Model\\Client\\Item\\AudioDevice')); parent::__construct($serviceLocator); }
public function testFetchColWithEmptyTable() { $table = new \ReflectionProperty('Database\\AbstractTable', 'table'); $table->setAccessible(true); $table->setValue($this->_table, 'test2'); $this->_table->initialize(); $this->assertSame(array(), $this->_table->fetchCol('col1')); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'subnet'; $this->_hydrator = new \Zend\Stdlib\Hydrator\ArraySerializable(); $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy(array('netid' => 'Address', 'mask' => 'Mask', 'name' => 'Name', 'num_inventoried' => 'NumInventoried', 'num_identified' => 'NumIdentified', 'num_unknown' => 'NumUnknown'))); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $serviceLocator->get('Model\\Network\\Subnet')); parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'virtualmachines'; $this->_hydrator = new \Zend\Stdlib\Hydrator\ArraySerializable(); $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy(array('name' => 'Name', 'status' => 'Status', 'subsystem' => 'Product', 'vmtype' => 'Type', 'uuid' => 'Uuid', 'vcpu' => 'NumCpus', 'memory' => 'GuestMemory'))); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $serviceLocator->get('Model\\Client\\Item\\VirtualMachine')); parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'monitors'; $this->_hydrator = new \Zend\Stdlib\Hydrator\ArraySerializable(); $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy(array('manufacturer' => 'Manufacturer', 'caption' => 'Description', 'serial' => 'Serial', 'description' => 'ProductionDate', 'type' => 'Type'))); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $serviceLocator->get('Model\\Client\\Item\\Display')); parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'memories'; $this->_hydrator = new \Zend\Stdlib\Hydrator\ArraySerializable(); $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy(array('numslots' => 'SlotNumber', 'type' => 'Type', 'capacity' => 'Size', 'speed' => 'Clock', 'caption' => 'Caption', 'description' => 'Description', 'serialnumber' => 'Serial'))); $this->_hydrator->addStrategy('Size', new \Database\Hydrator\Strategy\MemorySlots\Size()); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $serviceLocator->get('Model\\Client\\Item\\MemorySlot')); parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $map = array('id' => 'Id', 'firstname' => 'FirstName', 'lastname' => 'LastName', 'email' => 'MailAddress', 'comments' => 'Comment'); $this->_hydrator = new \Zend\Hydrator\ArraySerializable(); $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy($map)); $this->_hydrator->addFilter('whitelist', new \Library\Hydrator\Filter\Whitelist($map)); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $serviceLocator->get('Model\\Operator\\Operator')); parent::__construct($serviceLocator); }
/** * Sort results * * Default implementation: * - NULL: type specific default * - "id": item ID * - other: query table's hydrator for matching column name * * @param string $order Property to sort by * @param string $direction One of asc|desc */ public function order($order, $direction) { if (is_null($order)) { $tableClass = get_class($this->_table); $order = $this->_defaultOrder[substr($tableClass, strrpos($tableClass, '\\') + 1)]; } if ($order != 'id') { $order = $this->_table->getHydrator()->extractName($order); } $this->_select->order(array($this->_table->table . ".{$order}" => $direction)); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'regconfig'; $this->_hydrator = new \Zend\Hydrator\ArraySerializable(); $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy(array('id' => 'Id', 'name' => 'Name', 'regtree' => 'RootKey', 'regkey' => 'SubKeys', 'regvalue' => 'Value'))); $value = new \Database\Hydrator\Strategy\RegistryValueDefinitions\Value(); $this->_hydrator->addStrategy('Value', $value); $this->_hydrator->addStrategy('regvalue', $value); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $serviceLocator->get('Model\\Registry\\Value')); parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'videos'; $this->_hydrator = new \Zend\Stdlib\Hydrator\ArraySerializable(); $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy(array('name' => 'Name', 'chipset' => 'Chipset', 'memory' => 'Memory', 'resolution' => 'CurrentResolution'))); // Strategies are only required on hydration. Once sanitized, the // original values can be discarded. $this->_hydrator->addStrategy('Memory', new \Database\Hydrator\Strategy\DisplayControllers\Memory()); $this->_hydrator->addStrategy('CurrentResolution', new \Database\Hydrator\Strategy\DisplayControllers\CurrentResolution()); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $serviceLocator->get('Model\\Client\\Item\\DisplayController')); parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'download_available'; $map = array('name' => 'Name', 'fileid' => 'Id', 'priority' => 'Priority', 'fragments' => 'NumFragments', 'size' => 'Size', 'osname' => 'Platform', 'comment' => 'Comment', 'num_pending' => 'NumPending', 'num_running' => 'NumRunning', 'num_success' => 'NumSuccess', 'num_error' => 'NumError'); $this->_hydrator = new \Zend\Hydrator\ArraySerializable(); $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy($map)); $this->_hydrator->addFilter('whitelist', new \Library\Hydrator\Filter\Whitelist($map)); $platform = new \Database\Hydrator\Strategy\Packages\Platform(); $this->_hydrator->addStrategy('Platform', $platform); $this->_hydrator->addStrategy('osname', $platform); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $serviceLocator->get('Model\\Package\\Package')); parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'netmap'; $this->_hydrator = new \Zend\Hydrator\ArraySerializable(); $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy(array('ip' => 'IpAddress', 'mac' => 'MacAddress', 'name' => 'Hostname', 'date' => 'DiscoveryDate', 'description' => 'Description', 'type' => 'Type'))); $dateTimeFormatter = new \Zend\Hydrator\Strategy\DateTimeFormatterStrategy($serviceLocator->get('Database\\Nada')->timestampFormatPhp(), new \DateTimeZone('UTC')); $this->_hydrator->addStrategy('DiscoveryDate', $dateTimeFormatter); $this->_hydrator->addStrategy('date', $dateTimeFormatter); $macAddress = new \Library\Hydrator\Strategy\MacAddress(); $this->_hydrator->addStrategy('MacAddress', $macAddress); $this->_hydrator->addStrategy('mac', $macAddress); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $serviceLocator->get('Model\\Network\\Device')); parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public static function getObsoleteColumns($logger, $schema, $database) { $obsoleteColumns = parent::getObsoleteColumns($logger, $schema, $database); // Preserve columns which were added through the user interface. $preserveColumns = array(); // accountinfo_config may not exist yet when populating an empty // database. In that case, there are no obsolete columns. if (in_array('accountinfo_config', $database->getTableNames())) { $fields = $database->query("SELECT id FROM accountinfo_config WHERE name_accountinfo IS NULL AND account_type = 'COMPUTERS'"); foreach ($fields as $field) { $preserveColumns[] = "fields_{$field['id']}"; } } return array_diff($obsoleteColumns, $preserveColumns); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'networks'; $hydratorMap = array('description' => 'Description', 'speed' => 'Rate', 'macaddr' => 'MacAddress', 'ipaddress' => 'IpAddress', 'ipmask' => 'Netmask', 'ipgateway' => 'Gateway', 'ipsubnet' => 'Subnet', 'ipdhcp' => 'DhcpServer', 'status' => 'Status', 'type' => 'Type', 'typemib' => 'TypeMib', 'is_blacklisted' => 'IsBlacklisted'); // Don't extract the virtual IsBlacklisted property $extractorMap = array_flip($hydratorMap); unset($extractorMap['IsBlacklisted']); $this->_hydrator = new \Zend\Stdlib\Hydrator\ArraySerializable(); $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy($hydratorMap, $extractorMap)); $this->_hydrator->addFilter('whitelist', new \Library\Hydrator\Filter\Whitelist(array_keys($extractorMap))); $this->_hydrator->addStrategy('MacAddress', new \Library\Hydrator\Strategy\MacAddress()); $this->_hydrator->addStrategy('macaddr', new \Library\Hydrator\Strategy\MacAddress()); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $serviceLocator->get('Model\\Client\\Item\\NetworkInterface')); parent::__construct($serviceLocator); }
/** {@inheritdoc} */ public function initialize() { $this->_hydrator = new \Zend\Stdlib\Hydrator\ArraySerializable(); $this->_hydrator->setNamingStrategy(new \Database\Hydrator\NamingStrategy\MapNamingStrategy(array('id' => 'Id', 'name' => 'Name', 'description' => 'Description', 'lastdate' => 'CreationDate', 'request' => 'DynamicMembersSql', 'create_time' => 'CacheCreationDate', 'revalidate_from' => 'CacheExpirationDate'))); $dateTimeFormatter = new \Zend\Stdlib\Hydrator\Strategy\DateTimeFormatterStrategy($this->_serviceLocator->get('Database\\Nada')->timestampFormatPhp()); $this->_hydrator->addStrategy('CreationDate', $dateTimeFormatter); $this->_hydrator->addStrategy('lastdate', $dateTimeFormatter); $cacheCreationDateStrategy = new \Database\Hydrator\Strategy\Groups\CacheDate(); $this->_hydrator->addStrategy('CacheCreationDate', $cacheCreationDateStrategy); $this->_hydrator->addStrategy('create_time', $cacheCreationDateStrategy); $cacheExpirationDateStrategy = new \Database\Hydrator\Strategy\Groups\CacheDate($this->_serviceLocator->get('Model\\Config')->groupCacheExpirationInterval); $this->_hydrator->addStrategy('CacheExpirationDate', $cacheExpirationDateStrategy); $this->_hydrator->addStrategy('revalidate_from', $cacheExpirationDateStrategy); $this->resultSetPrototype = new \Zend\Db\ResultSet\HydratingResultSet($this->_hydrator, $this->_serviceLocator->get('Model\\Group\\Group')); return parent::initialize(); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'software_definitions'; parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'javainfos'; parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'accountinfo_config'; parent::__construct($serviceLocator); }
/** * Create/update all tables * * This method iterates over all JSON schema files in ./data, instantiates * table objects of the same name for each file and calls their setSchema() * method. * * @param bool $prune Drop obsolete tables/columns */ public function updateTables($prune) { $database = $this->_serviceLocator->get('Database\\Nada'); $handledTables = array(); $glob = new \GlobIterator(Module::getPath('data/Tables') . '/*.json'); foreach ($glob as $fileinfo) { $tableClass = $fileinfo->getBaseName('.json'); $table = $this->_serviceLocator->get('Database\\Table\\' . $tableClass); $table->setSchema($prune); $handledTables[] = $table->table; } // Views need manual invocation. $this->_serviceLocator->get('Database\\Table\\Clients')->setSchema(); $this->_serviceLocator->get('Database\\Table\\PackageDownloadInfo')->setSchema(); $this->_serviceLocator->get('Database\\Table\\WindowsInstallations')->setSchema(); $logger = $this->_serviceLocator->get('Library\\Logger'); // Server tables have no table class $glob = new \GlobIterator(Module::getPath('data/Tables/Server') . '/*.json'); foreach ($glob as $fileinfo) { $schema = \Zend\Config\Factory::fromFile($fileinfo->getPathname()); self::setSchema($logger, $schema, $database, \Database\AbstractTable::getObsoleteColumns($logger, $schema, $database), $prune); $handledTables[] = $schema['name']; } // SNMP tables have no table class $glob = new \GlobIterator(Module::getPath('data/Tables/Snmp') . '/*.json'); foreach ($glob as $fileinfo) { $schema = \Zend\Config\Factory::fromFile($fileinfo->getPathname()); $obsoleteColumns = \Database\AbstractTable::getObsoleteColumns($logger, $schema, $database); if ($schema['name'] == 'snmp_accountinfo') { // Preserve columns which were added through the user interface. $preserveColumns = array(); // accountinfo_config may not exist yet when populating an empty // database. In that case, there are no obsolete columns. if (in_array('accountinfo_config', $database->getTableNames())) { $customFieldConfig = $this->_serviceLocator->get('Database\\Table\\CustomFieldConfig'); $select = $customFieldConfig->getSql()->select(); $select->columns(array('id'))->where(array('name_accountinfo' => null, 'account_type' => 'SNMP')); foreach ($customFieldConfig->selectWith($select) as $field) { $preserveColumns[] = "fields_{$field['id']}"; } $obsoleteColumns = array_diff($obsoleteColumns, $preserveColumns); } } self::setSchema($logger, $schema, $database, $obsoleteColumns, $prune); $handledTables[] = $schema['name']; } // Detect obsolete tables that are present in the database but not in // any of the schema files. $obsoleteTables = array_diff($database->getTableNames(), $handledTables); foreach ($obsoleteTables as $table) { if ($prune) { $logger->notice("Dropping table {$table}..."); $database->dropTable($table); $logger->notice("Done."); } else { $logger->warn("Obsolete table {$table} detected."); } } }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'braintacle_windows'; parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'blacklist_macaddresses'; parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'braintacle_blacklist_assettags'; parent::__construct($serviceLocator); }
/** * {@inheritdoc} * @codeCoverageIgnore */ public function __construct(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) { $this->table = 'groups_cache'; parent::__construct($serviceLocator); }