/** * 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; }
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()); }
/** * 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); }