/**
  * Обновить запись.
  * Метод PUT для RESTfull.
  */
 public function update($id, $data)
 {
     $result = new JsonModel();
     $lincutConfigPath = $_SERVER["DOCUMENT_ROOT"] . "/lincut.config.php";
     // Создаем в памяти новый конфигурационный файл с новыми настройками
     $lincutConfigNew = new Config(array(), true);
     $lincutConfigNew->lincut = array();
     $lincutConfigNew->lincut->wkhtmltopdf = array();
     $lincutConfigNew->lincut->restriction = array();
     if (array_key_exists("wkhtmltopdf_path", $data)) {
         $lincutConfigNew->lincut->wkhtmltopdf->path = $data["wkhtmltopdf_path"];
     }
     if (array_key_exists("restriction_mode", $data)) {
         $lincutConfigNew->lincut->restriction->mode = $data["restriction_mode"];
     }
     if (array_key_exists("restriction_up_time", $data)) {
         $lincutConfigNew->lincut->restriction->uptime = $data["restriction_up_time"];
     }
     if (array_key_exists("restriction_up_count", $data)) {
         $lincutConfigNew->lincut->restriction->upcount = $data["restriction_up_count"];
     }
     if (array_key_exists("saw", $data)) {
         $lincutConfigNew->lincut->saw = $data["saw"];
     }
     if (array_key_exists("waste", $data)) {
         $lincutConfigNew->lincut->waste = $data["waste"];
     }
     $dbwcad = "db/wcad";
     $lincutConfigNew->db = array();
     $lincutConfigNew->db->adapters = array();
     $lincutConfigNew->db->adapters->{$dbwcad} = array();
     if (array_key_exists("db_wcad_servername", $data)) {
         $lincutConfigNew->db->adapters->{$dbwcad}->servername = $data["db_wcad_servername"];
     }
     if (array_key_exists("db_wcad_database", $data)) {
         $lincutConfigNew->db->adapters->{$dbwcad}->database = $data["db_wcad_database"];
     }
     if (array_key_exists("db_wcad_username", $data)) {
         $lincutConfigNew->db->adapters->{$dbwcad}->username = $data["db_wcad_username"];
     }
     if (array_key_exists("db_wcad_password", $data)) {
         $lincutConfigNew->db->adapters->{$dbwcad}->password = $data["db_wcad_password"];
     }
     // Открываем существующий файл настроек, если он имеется в наличии
     $lincutConfig = array();
     if (is_file($lincutConfigPath)) {
         $lincutConfig = \Zend\Config\Factory::fromFile($lincutConfigPath);
     }
     $lincutConfig = new Config($lincutConfig, true);
     $lincutConfig->merge($lincutConfigNew);
     // Сохраняем настройки
     $writer = new \Zend\Config\Writer\PhpArray();
     $writer->toFile($lincutConfigPath, $lincutConfig);
     // Возвращаем результат операции
     $result->success = true;
     return $result;
 }
Beispiel #2
0
 private function generateConfigFile(Config $new_config)
 {
     $config_file = 'config/autoload/local.php';
     // If there is a config file at that path, so merge the configuration to it.
     $config = array();
     if (file_exists($config_file)) {
         $config = (include $config_file);
     }
     $reader = new Config($config);
     $reader->merge($new_config);
     $writer = new \Zend\Config\Writer\PhpArray();
     $writer->toFile($config_file, $reader);
 }
Beispiel #3
0
 public function updateapps($get, $post)
 {
     if (!Ui::API_UPDATEAPPS) {
         return Ui::API_RETURN_FORBIDDEN;
     }
     // note 写 app 缓存文件
     $cachefile = getcwd() . '/data/cache/ucenter_apps.php';
     $config = new \Zend\Config\Config($post, true);
     $writer = new \Zend\Config\Writer\PhpArray();
     $writer->toFile($cachefile, $config);
     // TODO note 写配置文件
     return Ui::API_RETURN_SUCCEED;
 }
/**
 * Checks total platform size
 * @param bool $debug
 *
 * @return bool
 */
function isTotalPortalSizeBiggerThanLimit($debug = true)
{
    $sizeLimit = api_get_configuration_value('hosting_total_size_limit');
    if (empty($sizeLimit)) {
        return true;
    }
    $updateFile = true;
    $file = api_get_path(SYS_COURSE_PATH) . 'hosting_total_size.php';
    // Default data
    $hostingData = array('frequency' => 86400);
    $log = null;
    // Check if file exists and if it is updated
    if (file_exists($file)) {
        $hostingDataFromFile = (require $file);
        // Check time() is UTC
        if (isset($hostingDataFromFile['updated_at']) && isset($hostingDataFromFile['frequency']) && isset($hostingDataFromFile['size'])) {
            $hostingData = $hostingDataFromFile;
            $time = $hostingData['updated_at'] + $hostingData['frequency'];
            $diff = $time - time();
            if ($time > time()) {
                $log .= "You need to wait {$diff} seconds to update the file \n";
                $updateFile = false;
            }
        }
    }
    // Now get values for total portal size
    $log .= "Frequency loaded: " . $hostingData['frequency'] . "\n";
    if ($updateFile) {
        $log .= "Updating total size ... \n";
        $totalSize = calculateTotalPortalSize($debug);
        $log .= "Total size calculated: {$totalSize} \n";
        $hostingData['updated_at'] = time();
        $hostingData['size'] = $totalSize;
        $writer = new Zend\Config\Writer\PhpArray();
        $phpCode = $writer->toString($hostingData);
        file_put_contents($file, $phpCode);
        $log .= "File saved in {$file} \n";
    } else {
        $log .= "Total size not updated \n";
        $totalSize = $hostingData['size'];
    }
    $result = true;
    if ($totalSize > $sizeLimit) {
        $log .= "Current total size of {$totalSize} MB is bigger than limit: {$sizeLimit} MB \n";
        $result = false;
    }
    if ($debug) {
        echo $log;
    }
    return $result;
}
 /**
  *
  * @param array $params
  * @param string $posts
  */
 public function processRequest(array $params = null, $posts = null)
 {
     try {
         $filter = new \Zend\I18n\Filter\Alnum();
         $name = $filter->filter($posts['collectionfilename']);
         $config = new \Zend\Config\Config(array(), true);
         $config->path = '/data/assets/' . $name;
         $config->web = '/assets/app';
         $config->collections = array();
         $styles = $name . 'styles';
         // $config->collections = $styles;
         $config->collections->{$styles} = array();
         $config->collections->{$styles}->debug = false;
         $config->collections->{$styles}->area = 'styles';
         $config->collections->{$styles}->type = 'styles';
         $config->collections->{$styles}->attr = array();
         $config->collections->{$styles}->attr->media = 'all';
         $config->collections->{$styles}->attr->rel = 'stylesheet';
         $config->collections->{$styles}->assets = array();
         $config->collections->{$styles}->includes = array();
         $config->collections->{$styles}->includes[] = '/data/usr/share/min/css/cssmin-v3.0.1.php';
         $config->collections->{$styles}->filters = array();
         $config->collections->{$styles}->filters->mincss = 'Assetic\\Filter\\CssMinFilter';
         $header = $name . 'header';
         $config->collections->{$header} = array();
         $config->collections->{$header}->debug = false;
         $config->collections->{$header}->area = 'head';
         $config->collections->{$header}->type = 'js';
         $config->collections->{$header}->attr = array();
         $config->collections->{$header}->attr->type = 'text/javascript';
         $config->collections->{$header}->assets = array();
         $scripts = $name . 'scripts';
         $config->collections->{$scripts} = array();
         $config->collections->{$scripts}->debug = false;
         $config->collections->{$scripts}->area = 'head';
         $config->collections->{$scripts}->type = 'js';
         $config->collections->{$scripts}->attr = array();
         $config->collections->{$scripts}->attr->type = 'text/javascript';
         $config->collections->{$scripts}->assets = array();
         $config->collections->{$scripts}->includes = array();
         $config->collections->{$scripts}->includes[] = '/data/usr/share/min/js/JSMin.php';
         $config->collections->{$scripts}->filters = array();
         $config->collections->{$scripts}->filters->minjs = 'Assetic\\Filter\\JSMinFilter';
         $writer = new \Zend\Config\Writer\PhpArray();
         $writer->toFile(CON_ROOT_PATH . DS . 'data/assets/templates' . DS . $name . '.php', $config);
         return array('success' => true);
     } catch (\Exception $e) {
         return array('error' => $e->getMessage());
     }
 }
 public function buildRoute()
 {
     $config = $this->getProjectConfig();
     $writer = new \Zend\Config\Writer\PhpArray();
     // Need to do some error checking it has happened a couple times where this came through without having router routes
     foreach ($config->router->routes as $name => $object) {
         if ($this->routeObject->get('RouteName') == $name) {
             throw new \Exception('I found a route with the same name.  Run `route:update` to modify this route.');
         }
     }
     $routes = $this->mergeRoute($config->router->routes);
     $config->router->routes->merge($routes);
     $this->configHelper->newConfigToFile($config);
     return $writer->toString($this->getRoute());
 }
 /**
  * 
  * @param unknown $name
  */
 public function create($name)
 {
     $config = new \Zend\Config\Config(array(), true);
     $config->path = '/data/assets/' . $name;
     $config->web = '/assets/app';
     $config->collections = array();
     $styles = $name . 'styles';
     // $config->collections = $styles;
     $config->collections->{$styles} = array();
     $config->collections->{$styles}->debug = false;
     $config->collections->{$styles}->area = 'styles';
     $config->collections->{$styles}->type = 'styles';
     $config->collections->{$styles}->attr = array();
     $config->collections->{$styles}->attr->media = 'all';
     $config->collections->{$styles}->attr->rel = 'stylesheet';
     $config->collections->{$styles}->assets = array();
     $config->collections->{$styles}->includes = array();
     $config->collections->{$styles}->includes[] = '/data/usr/share/min/css/cssmin-v3.0.1.php';
     $config->collections->{$styles}->filters = array();
     $config->collections->{$styles}->filters->mincss = 'Assetic\\Filter\\CssMinFilter';
     $header = $name . 'header';
     $config->collections->{$header} = array();
     $config->collections->{$header}->debug = false;
     $config->collections->{$header}->area = 'head';
     $config->collections->{$header}->type = 'js';
     $config->collections->{$header}->attr = array();
     $config->collections->{$header}->attr->type = 'text/javascript';
     $config->collections->{$header}->assets = array();
     $scripts = $name . 'scripts';
     $config->collections->{$scripts} = array();
     $config->collections->{$scripts}->debug = false;
     $config->collections->{$scripts}->area = 'head';
     $config->collections->{$scripts}->type = 'js';
     $config->collections->{$scripts}->attr = array();
     $config->collections->{$scripts}->attr->type = 'text/javascript';
     $config->collections->{$scripts}->assets = array();
     $config->collections->{$scripts}->includes = array();
     $config->collections->{$scripts}->includes[] = '/data/usr/share/min/js/JSMin.php';
     $config->collections->{$scripts}->filters = array();
     $config->collections->{$scripts}->filters->minjs = 'Assetic\\Filter\\JSMinFilter';
     $writer = new \Zend\Config\Writer\PhpArray();
     $writer->toFile(CON_ROOT_PATH . DS . 'data/assets/templates' . DS . $name . '.php', $config);
 }
 /**
  *
  * @param array $params
  * @param string $posts
  */
 public function processRequest(array $params = null, $posts = null)
 {
     try {
         $config = new \Zend\Config\Config(include CON_ROOT_PATH . DS . $this->getEntity()->getCurrentPath() . DS . $posts['ident'] . '.php', true);
         $filter = new \Zend\I18n\Filter\Alnum();
         $name = $filter->filter($posts['collectionname']);
         $save = false;
         switch ($posts['collectiontype']) {
             case 'styles':
                 $save = true;
                 $styles = $name . 'styles';
                 $config->collections->{$styles} = array();
                 $config->collections->{$styles}->debug = false;
                 $config->collections->{$styles}->area = 'styles';
                 $config->collections->{$styles}->type = 'styles';
                 $config->collections->{$styles}->attr = array();
                 $config->collections->{$styles}->attr->media = 'all';
                 $config->collections->{$styles}->attr->rel = 'stylesheet';
                 $config->collections->{$styles}->assets = array();
                 $config->collections->{$styles}->includes = array();
                 $config->collections->{$styles}->includes[] = '/data/usr/share/min/css/cssmin-v3.0.1.php';
                 $config->collections->{$styles}->filters = array();
                 $config->collections->{$styles}->filters->mincss = 'Assetic\\Filter\\CssMinFilter';
                 break;
             case 'scripts':
                 $save = true;
                 $scripts = $name . 'scripts';
                 $config->collections->{$scripts} = array();
                 $config->collections->{$scripts}->debug = false;
                 $config->collections->{$scripts}->area = 'head';
                 $config->collections->{$scripts}->type = 'js';
                 $config->collections->{$scripts}->attr = array();
                 $config->collections->{$scripts}->attr->type = 'text/javascript';
                 $config->collections->{$scripts}->assets = array();
                 $config->collections->{$scripts}->includes = array();
                 $config->collections->{$scripts}->includes[] = '/data/usr/share/min/js/JSMin.php';
                 $config->collections->{$scripts}->filters = array();
                 $config->collections->{$scripts}->filters->minjs = 'Assetic\\Filter\\JSMinFilter';
                 break;
             case 'header':
                 $save = true;
                 $header = $name . 'header';
                 $config->collections->{$header} = array();
                 $config->collections->{$header}->debug = false;
                 $config->collections->{$header}->area = 'head';
                 $config->collections->{$header}->type = 'js';
                 $config->collections->{$header}->attr = array();
                 $config->collections->{$header}->attr->type = 'text/javascript';
                 $config->collections->{$header}->assets = array();
                 break;
             default:
                 break;
         }
         if (true === $save) {
             $writer = new \Zend\Config\Writer\PhpArray();
             $writer->toFile(CON_ROOT_PATH . DS . $this->getEntity()->getCurrentPath() . DS . $posts['ident'] . '.php', $config);
             return array('success' => true);
         } else {
             return array('warn' => 'wrong_parameter');
         }
     } catch (\Exception $e) {
         return array('error' => $e->getMessage());
     }
 }
Beispiel #9
0
 /**
  * Updates the configuration.yml file
  *
  * @param OutputInterface $output
  * @param bool $dryRun
  * @param array $newValues
  * @return bool
  */
 public function updateConfiguration(OutputInterface $output, $dryRun, $newValues)
 {
     $this->getConfigurationPath();
     $_configuration = $this->getConfigurationArray();
     // Merging changes
     if (!empty($newValues)) {
         $_configuration = array_merge($_configuration, $newValues);
     }
     $paramsToRemove = array('tracking_enabled', 'db_prefix', 'statistics_database', 'user_personal_database', 'scorm_database');
     foreach ($_configuration as $key => $value) {
         if (in_array($key, $paramsToRemove)) {
             unset($_configuration[$key]);
         }
     }
     // See http://zf2.readthedocs.org/en/latest/modules/zend.config.introduction.html
     $config = new \Zend\Config\Config($_configuration, true);
     $writer = new \Zend\Config\Writer\PhpArray();
     $content = $writer->toString($config);
     $content = str_replace('return', '$_configuration = ', $content);
     $configurationPath = $this->getConfigurationPath();
     $newConfigurationFile = $configurationPath . 'configuration.php';
     if ($dryRun == false) {
         if (version_compare($newValues['system_version'], '1.10', '>=') || ($newValues['system_version'] == '1.10.x' || $newValues['system_version'] == '1.11.x')) {
             $configurationPath = $_configuration['root_sys'] . 'app/config/';
             $newConfigurationFile = $configurationPath . 'configuration.php';
         }
         file_put_contents($newConfigurationFile, $content);
         $output->writeln("<comment>File updated: {$newConfigurationFile}</comment>");
     } else {
         $output->writeln("<comment>File to be updated (dry-run is on): {$newConfigurationFile}</comment>");
         $output->writeln($content);
     }
     return file_exists($newConfigurationFile);
 }
Beispiel #10
0
 /**
  * Write configuration.
  *
  * @param Config $config
  * @param string|null $file
  */
 public function writeConfiguration(Config $config, $file = null)
 {
     if ($file === null) {
         $file = $this['configPath'];
     }
     $writer = new \Zend\Config\Writer\PhpArray();
     $writer->toFile($file, $config);
     // clear apc cache entry
     if (function_exists('apc_delete_file')) {
         @apc_delete_file($file);
     } else {
         if (function_exists('apc_clear_cache')) {
             @apc_clear_cache();
         }
     }
 }
<?php

/**
 * @var \OpsWay\AppManager\Service\Manager $this
 */
$console = $this->getServiceLocator()->get('console');
//$console->clear();
/**
 * @var \Zend\Mvc\Controller\AbstractActionController $controller
 */
$controller = $e->getParam('controller');
$consoleParams = [];
parse_str($controller->getRequest()->getParam('params', ''), $consoleParams);
// SETUP LOCAL CONFIG
$localConfig = new \Zend\Config\Config(include getcwd() . '/config/autoload/local.php.dist', true);
$dbConfig = $localConfig->doctrine->connection->orm_default->params;
foreach (['host', 'port', 'user', 'password', 'dbname'] as $pName) {
    if (isset($consoleParams['db']) && isset($consoleParams['db'][$pName])) {
        $dbConfig->{$pName} = $consoleParams['db'][$pName];
    } else {
        $dbConfig->{$pName} = ($value = \Zend\Console\Prompt\Line::prompt("DATABASE. Please enter {$pName} [" . $dbConfig->{$pName} . "]:", true, 100)) ? $value : $dbConfig->{$pName};
    }
}
$writer = new \Zend\Config\Writer\PhpArray();
$writer->setUseBracketArraySyntax(true);
$writer->toFile(getcwd() . '/config/autoload/local/db.local.php', $localConfig);
$console->writeLine('Database configuration file created!');
Beispiel #12
0
#!/usr/bin/env php
<?php 
if (file_exists(__DIR__ . '/../../../autoload.php')) {
    include_once __DIR__ . '/../../../autoload.php';
}
$collector = new TweeCdn\Hash\Collector(__DIR__ . '/../../../../public');
$hashes = $collector->collect();
$writer = new Zend\Config\Writer\PhpArray();
$writer->toFile(__DIR__ . '/../tmp/hashes.php', $hashes);