/** * @param string $realm * * @return KVMLogger */ public static function createWithKLogger($path, $logLevelThreshold = LogLevel::DEBUG, $realm = 'application', $options = ['filename' => 'kvm.log']) { $kLogger = new Logger($path, LogLevel::DEBUG, $options); $kvmLogger = new KVMLogger($realm); $kvmLogger->addLogger($kLogger, $logLevelThreshold); return $kvmLogger; }
/** * @return Client */ public function getClient() { if (!$this->client) { $client = new Client(['base_url' => $this->getConfiguration()->getUri(), 'defaults' => ['timeout' => $this->getConfiguration()->getTimeout()]]); $this->client = $client; $emitter = $client->getEmitter(); $emitter->on('end', function (EndEvent $event) { $kvm = KVMLogger::instance('anycontent-connection'); $message = new LogMessage(); $message->addLogValue('method', $event->getRequest()->getMethod()); $response = $event->getResponse(); if ($response) { $duration = (int) ($event->getTransferInfo('total_time') * 1000); $message->addLogValue('code', $response->getStatusCode()); $message->addLogValue('duration', $duration); $message->addLogValue('url', $response->getEffectiveUrl()); $kvm->debug($message); } else { $message->addLogValue('url', $event->getRequest()->getUrl()); $message->addLogValue('exception', $event->getException()->getCode() . ': ' . $event->getException()->getMessage()); $kvm->error($message); } }); } return $this->client; }
/** * * @return $this * @throws AnyContentClientException */ public function addConfigType($configTypeName, $filenameCMDL, $filenameRecord) { $fs = new Filesystem(); if (!$fs->exists($filenameCMDL)) { KVMLogger::instance('anycontent-connection')->info('File ' . $filenameCMDL . ' not found.'); } if (!$fs->exists($filenameRecord)) { KVMLogger::instance('anycontent-connection')->info('File ' . $filenameRecord . ' not found.'); } $this->configTypes[$configTypeName] = ['record' => $filenameRecord, 'cmdl' => $filenameCMDL]; return $this; }
/** * @param $sql * @param array $params * * @return \PDOStatement */ public function execute($sql, $params = array()) { $kvm = KVMLogger::instance('anycontent-database'); /** @var \PDO $db */ $dbh = $this->getConnection(); $stmt = $dbh->prepare($sql); $kvm->startStopWatch('anycontent-query-execution-time'); $stmt->execute($params); $duration = $kvm->getDuration('anycontent-query-execution-time'); $message = $kvm->createLogMessage($this->debugQuery($sql, $params), ['duration' => $duration]); $kvm->debug($message); return $stmt; }
public function testGetRecords() { KVMLogger::instance()->debug(__METHOD__); $connection = $this->connection; $connection->selectContentType('profiles'); $records = $connection->getAllRecords(); $this->assertCount(608, $records); foreach ($records as $record) { $id = $record->getId(); $fetchRecord = $connection->getRecord($id); $this->assertEquals($id, $fetchRecord->getId()); } }
/** * Tests if an entry exists in the cache. * * @param string $id The cache id of the entry to check for. * * @return boolean TRUE if a cache entry exists for the given cache id, FALSE otherwise. */ protected function doContains($id) { $md5Key = md5($id); $kvm = KVMLogger::instance('anycontent-cache'); $hit = $this->getCacheProvider()->doContains($md5Key); if ($hit) { $this->hit++; $message = $kvm->createLogMessage('Cache hit', ['key' => $id, 'md5' => $md5Key, 'namespace' => $this->getNamespace()]); $kvm->debug($message); } else { $this->miss++; $message = $kvm->createLogMessage('Cache miss', ['key' => $id, 'namespace' => $this->getNamespace()]); $kvm->debug($message); } return $hit; }
public function testGetRecords() { KVMLogger::instance()->debug(__METHOD__); $connection = $this->connection; if (!$connection) { $this->markTestSkipped('RestLike Basic Connection credentials missing.'); } $connection->selectContentType('dtag_searchresult_product'); $records = $connection->getAllRecords(); $this->assertCount(149, $records); foreach ($records as $record) { $id = $record->getId(); $fetchRecord = $connection->getRecord($id); $this->assertEquals($id, $fetchRecord->getId()); } }
/** * @param $recordId * * @return Record * @throws AnyContentClientException */ public function getRecord($recordId, $contentTypeName = null, DataDimensions $dataDimensions = null) { if ($contentTypeName == null) { $contentTypeName = $this->getCurrentContentTypeName(); } if ($dataDimensions == null) { $dataDimensions = $this->getCurrentDataDimensions(); } $folder = $this->getConfiguration()->getFolderNameRecords($contentTypeName, $dataDimensions); $fileName = $folder . '/' . $recordId . '.json'; if ($this->fileExists($fileName)) { $data = $this->readRecord($fileName); if ($data) { $data = json_decode($data, true); $definition = $this->getContentTypeDefinition($contentTypeName); $record = $this->getRecordFactory()->createRecordFromJSON($definition, $data, $dataDimensions->getViewName(), $dataDimensions->getWorkspace(), $dataDimensions->getLanguage()); return $this->exportRecord($record, $dataDimensions->getViewName()); } } KVMLogger::instance('anycontent-connection')->info('Record ' . $recordId . ' not found for content type ' . $this->getCurrentContentTypeName()); return false; }
protected function readData($fileName) { if ($this->fileExists($fileName)) { return file_get_contents($fileName); } KVMLogger::instance('anycontent-connection')->warning('Could not open file ' . $fileName); return false; }
protected function getMultiViewConfig($configTypeName, DataDimensions $dataDimensions) { $tableName = $this->getConfigTypeTableName(); $database = $this->getDatabase(); $timestamp = TimeShifter::getTimeshiftTimestamp($dataDimensions->getTimeShift()); $sql = 'SELECT * FROM ' . $tableName . ' WHERE id = ? AND workspace = ? AND language = ? AND validfrom_timestamp <= ? AND validuntil_timestamp > ?'; $rows = $database->fetchAllSQL($sql, [$configTypeName, $dataDimensions->getWorkspace(), $dataDimensions->getLanguage(), $timestamp, $timestamp]); if (count($rows) == 1) { $row = reset($rows); $config = $this->createConfigFromRow($row, $configTypeName, $dataDimensions); } else { $definition = $this->getConfigTypeDefinition($configTypeName); $config = $this->getRecordFactory()->createConfig($definition); KVMLogger::instance('anycontent-connection')->info('Config ' . $configTypeName . ' not found'); } return $config; }
public function registerRecordClassForConfigType($configTypeName, $classname) { if ($this->hasConfigType($configTypeName)) { $this->getRecordFactory()->registerRecordClassForConfigType($configTypeName, $classname); KVMLogger::instance('anycontent-repository')->info('Custom record class ' . $classname . ' for config type ' . $configTypeName); return true; } return false; }
public function testDeleteAllRecordsNewConnection() { KVMLogger::instance()->debug(__METHOD__); $connection = $this->connection; $connection->selectContentType('profiles'); $this->assertEquals(0, $connection->countRecords()); }
$app['env'] = 'prod'; } $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Core\\Init'); $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Core\\Layout'); $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Core\\Repositories'); $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Core\\Context'); $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Core\\Menu'); $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Core\\Listing'); $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Core\\Pager'); $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Core\\Sort'); $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Core\\Edit'); $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Core\\Start'); $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Core\\Config'); $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Core\\Files'); $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Core\\TimeShift'); $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Core\\WorkspacesLanguages'); $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Core\\User'); $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Libs\\BlockUI'); $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Libs\\BootstrapFormHelpers'); $app->registerModule('AnyContent\\CMCK\\Modules\\Backend\\Libs\\NestedSortable'); require_once APPLICATION_PATH . '/config/modules.php'; $app->initModules(); if ($app['env'] == 'test' || $app['env'] == 'console') { return $app; } if (file_exists(APPLICATION_PATH . '/config/repositories.php')) { require_once APPLICATION_PATH . '/config/repositories.php'; } $app->run(); \KVMLogger\KVMLogger::instance()->logResources();
public function testGetFilteredRecords() { KVMLogger::instance()->debug(__METHOD__); $connection = $this->connection; if (!$connection) { $this->markTestSkipped('RestLike Basic Connection credentials missing.'); } $repository = new Repository('pidtag', $connection); $connection->selectContentType('dtag_searchresult_product'); $records = $repository->getRecords(); $this->assertCount(149, $records); $records = $repository->getRecords('name *= apple'); $this->assertCount(10, $records); $records = $repository->getRecords('name = banana'); $this->assertCount(0, $records); }