public function testSetType() { $register = new SystemRegister('AppData'); $register->test1->value1->type = 'number'; // $this->assertEquals('number', $register->get('test1/value1')->type); }
/** * Генерирует файл сайтмапа */ public static function generate() { $register = new SystemRegister('System/Sitemap'); if ($register->get('sitemap.xml')->value == 0) { return; } // Получаем все url сайта $sql = 'SELECT * FROM `' . SITEMAP_TABLE . '` where `visible`="1"'; $aSitemap = DB::query($sql); // $xmlDocument = new DOMDocument('1.0', 'utf-8'); // $urlset = $xmlDocument->createElement('urlset'); $urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); foreach ($aSitemap as $row) { $url = $xmlDocument->createElement('url'); $loc = $xmlDocument->createElement('loc'); $lastmod = $xmlDocument->createElement('lastmod'); $changefreq = $xmlDocument->createElement('changefreq'); $priority = $xmlDocument->createElement('priority'); $loc->nodeValue = \Extasy\CMS::getWWWRoot() . substr($row['full_url'], 1); $lastmod->nodeValue = $row['date_updated']; $changefreq->nodeValue = $row['sitemap_xml_change']; $priority->nodeValue = $row['sitemap_xml_priority']; $url->appendChild($loc); $url->appendChild($lastmod); $url->appendChild($changefreq); $url->appendChild($priority); $urlset->appendChild($url); } $xmlDocument->appendChild($urlset); // Пишем в папку xml $xmlContents = $xmlDocument->saveXML(); file_put_contents(FILE_PATH . 'sitemap.xml', $xmlContents); }
/** * Тест установки sitemap-индекса к конфигу */ public function testSelectControlNames() { SystemRegisterSample::clearCache(); $fileList = \DAO_FileSystem::getInstance()->getFileList(LIB_PATH . 'custom_config/controls/'); $list = CConfigControlManager::selectAll(); $this->assertEquals(sizeof($fileList), sizeof($list)); // Добавляем в реестр файлег, но не пишем класс $path = LIB_PATH . 'custom_config/test.php'; $register = new SystemRegister('Applications/cconfig/user_control_path'); $register->insert('test', $path, ''); file_put_contents($path, ''); $list = CConfigControlManager::selectAll(); $this->assertEquals(sizeof($fileList), sizeof($list)); // Заполняем инфо о классе, таким образом класс становится доступным $path = 'custom_config/test2.php'; $contents = <<<EOD <? class CConfigControl_Test2 extends CConfigBaseControl { \tpublic function getXType() { \t\treturn "test2"; \t} } ?> EOD; file_put_contents(LIB_PATH . $path, $contents); $register->insert('test2', $path, ''); $list = CConfigControlManager::selectAll(); $this->assertEquals(sizeof($fileList) + 1, sizeof($list)); }
/** * Очищаем системный реестр */ protected function clearSystemRegister() { SystemRegisterSample::clearCache(); $register = new SystemRegister('Applications/cconfig'); $register->delete('user_control_path'); SystemRegisterSample::clearCache(); $register->insert('user_control_path', null, '', SYSTEMREGISTER_BRANCH_TYPE); }
/** * Тестирование удаления элементов */ public function testDelete() { $register = new SystemRegister('/AppData'); // $register->delete('test1/value1'); // try { $szValue = $register->test1->value1->value; $this->Fail('Property must be deleted'); } catch (SystemRegisterException $e) { } }
/** * Проверяем удаляется ли из кеша * @expectedException SystemRegisterException */ public function testCacheOnDeletedItem() { $register = new SystemRegister(); $register->insert('AppData/test1/new_value', 'New Value'); // $szValue = $register->get('AppData/test1/new_value'); // $test1 = $register->get('AppData/test1'); $register->delete('AppData/test1/new_value'); // $test1->get('new_value'); }
protected static function outputSitemapXML() { $register = new SystemRegister('System/Sitemap/'); if ($register->get('sitemap.xml')->value) { require_once CONTROL_PATH . 'input.php'; require_once CONTROL_PATH . 'select.php'; // $priority = new CInput(); $priority->name = 'sitemap_xml[priority]'; $priority->value = self::$sitemap['sitemap_xml_priority']; $changefreq = new CSelect(); $changefreq->items = array(array('id' => 'always', 'name' => 'Всегда'), array('id' => 'hourly', 'name' => 'Почасово'), array('id' => 'daily', 'name' => 'Ежедневно'), array('id' => 'weekly', 'name' => 'Еженедельно'), array('id' => 'monthly', 'name' => 'Ежемесячно'), array('id' => 'yearly', 'name' => 'Ежегодно'), array('id' => 'never', 'name' => 'Никогда')); $changefreq->name = 'sitemap_xml[change]'; $changefreq->current = self::$sitemap['sitemap_xml_change']; $design = CMSDesign::getInstance(); $design->header('Sitemap.XML'); $design->tableBegin(); $design->row2cell('Приоритет', $priority->generate()); $design->row2cell('Частота', $changefreq->generate()); $design->TableEnd(); } }
protected function displayRights($rightsString) { // Получаем все права существующие в системе $register = new SystemRegister('System/CMS/userRights'); $fullRightsList = SystemRegisterHelper::exportData($register->getId()); $usersRights = explode("\r\n", $rightsString); // Перебор прав $result = array(); foreach ($fullRightsList as $key => $row) { $checkbox = new CCheckbox(); $checkbox->name = 'rights[]'; $checkbox->value = $key; $checkbox->title = $row['comment']; if (in_array($key, $usersRights)) { $checkbox->checked = true; } $result[] = $checkbox; } return implode('<br/>', $result); }
<?php namespace Extasy\tests\Audit; use Faid\DBSimple; use Extasy\tests\Helper as TestsHelper; use UserAccount; use ACL; use Extasy\Audit\Api\ApiOperation; use Extasy\Audit\Record; use Extasy\Audit\Log; use Extasy\tests\system_register\Restorator; use Extasy\Columns\Password as passwordColumn; $register = new \SystemRegister('/System/'); try { $register->delete('Audit'); } catch (\Exception $e) { } Restorator::restore(); \SystemRegisterSample::createCache(); TestsHelper::dbFixture(ACL_TABLE, array()); ACL::create(ApiOperation::RightName); // user record TestsHelper::dbFixture(USERS_TABLE, array(array('login' => 'login', 'password' => passwordColumn::hash('testtest')), array('login' => 'guest', 'password' => passwordColumn::hash('testtest')))); // grant user permission $user = UserAccount::getByLogin('login'); ACL::grant(ApiOperation::RightName, $user->obj_rights->getEntity()); \UsersLogin::login('login', 'testtest'); // base logs TestsHelper::dbFixture(Log::getTableName(), array(array('name' => 'Log1', 'critical' => 0, 'enable_logging' => 1), array('name' => 'Log2', 'critical' => 1, 'enable_logging' => 1))); // base records
protected static function loadConfig() { $register = new \SystemRegister(self::SystemRegisterPath); self::$config = \SystemRegisterHelper::exportData($register->getId()); }
public function testImportUpdatingFileCacheWithDeletion() { $system = new SystemRegister('/System/'); $this->assertEquals(false, isset($system->array)); SystemRegisterHelper::import($system, array('XX' => '1', 'yy' => '2', 'Gisma' => 'rulit!', 'array' => array('0' => 'value1', '1' => array('1' => '2', '3' => '4')))); $this->assertEquals(true, isset($system->array)); // SystemRegisterSample::loadAll(); $base = new SystemRegister('System'); $this->assertEquals(true, isset($system->array)); $base->delete('array'); $this->assertEquals(false, isset($base->array)); // SystemRegisterSample::clearCache(); SystemRegisterSample::loadAll(); $system = new SystemRegister('/System/'); $this->assertEquals(false, isset($base->array)); }
/** * @expectedException SystemRegisterException */ public function testfChild() { $register = new SystemRegister('/AppData'); // Некорректный вызов $register->get('test1/value2'); }
/** * Обновляет лист в бд */ public static function update(SystemRegister $parent, $id, $szName, $szValue, $szComment, $szType) { // Экранируем переменные $id = intval($id); $szName = \Faid\DB::escape($szName); $szValue = \Faid\DB::escape($szValue); $szComment = \Faid\DB::escape($szComment); $szType = \Faid\DB::escape($szType); // запрос $sql = 'UPDATE `%s` SET `name`="%s",`value`="%s",`comment`="%s",`type`="%s" WHERE `id`="%s"'; $sql = sprintf($sql, SYSTEMREGISTER_TABLE, $szName, $szValue, $szComment, $szType, $id); // DB::post($sql); // обновляем кеш предка self::updateChildCache($parent->getId()); self::updateGetCache($szName, $parent->getId()); return $id; }
public static function getRootDocuments() { $register = new SystemRegister(self::RootDocumentsKey); return SystemRegisterHelper::export($register->getId()); }
/** * Возвращает имена классов всех контролов, с которыми в данный момент работает CConfig * @return array */ public static function selectAll() { // Грузим все файлы в папке контролов $files = DAO::getInstance('fs')->getFileList(CCONFIG_CONTROLS_PATH); $result = array(); foreach ($files as $row) { try { $row = basename($row, '.php'); $result[$row] = self::loadControl($row); } catch (Exception $e) { } } // Дополняем классами, записанными в реестре $register = new SystemRegister('Applications/cconfig/user_control_path'); $paths = SystemRegisterSample::selectChild($register->getId()); foreach ($paths as $row) { try { $result[$row['name']] = self::loadControl($row['name']); } catch (Exception $e) { } } return $result; }
<?php $register = new SystemRegister('/System/CMS'); $register->delete('Menu'); $register->delete('routes'); SystemRegisterSample::createCache();
/** * Возвращает значение указанного элемента системного реестра * @param $path * @return string */ public static function getValue($path) { $register = new SystemRegister('/'); return $register->get($path)->value; }
<?php $register = new SystemRegister('System/CMS'); $register->delete('display_administrate_scripts'); SystemRegisterSample::clearCache();
<?php $register = new SystemRegister('/System/CMS/routes/administrate'); $register->insert('audit', 'class://Extasy\\Audit\\Controllers\\Audit/startup'); SystemRegisterSample::createCache();