parent
74ef926fef
commit
36ef351507
@ -0,0 +1,120 @@ |
||||
<?php |
||||
|
||||
namespace Chash\Command\Files; |
||||
|
||||
use Chash\Command\Database\CommonChamiloDatabaseCommand; |
||||
use Symfony\Component\Console\Command\Command; |
||||
use Symfony\Component\Console\Input\InputArgument; |
||||
use Symfony\Component\Console\Input\InputInterface; |
||||
use Symfony\Component\Console\Input\InputOption; |
||||
use Symfony\Component\Console\Output\OutputInterface; |
||||
|
||||
/** |
||||
* Class UpdateDirectoryMaxSizeCommand |
||||
* Increase the maximum space allowed on disk progressively. This command is |
||||
* used called once every night, to make a "progressive increase" of space which |
||||
* will block abuse attempts, but still provide enough space to all courses to |
||||
* continue working progressively. |
||||
* @package Chash\Command\Files |
||||
*/ |
||||
class UpdateDirectoryMaxSizeCommand extends CommonChamiloDatabaseCommand |
||||
{ |
||||
/** |
||||
* |
||||
*/ |
||||
protected function configure() |
||||
{ |
||||
parent::configure(); |
||||
$this |
||||
->setName('files:update_directory_max_size') |
||||
->setAliases(array('fudms')) |
||||
->setDescription('Increases the max disk space for all the courses reaching a certain threshold. Max space needs to be of at least 1MB for each course first.') |
||||
->addOption( |
||||
'threshold', |
||||
null, |
||||
InputOption::VALUE_NONE, |
||||
'Sets the threshold, in %, above which a course size should be automatically increased' |
||||
) |
||||
->addOption( |
||||
'add-size', |
||||
null, |
||||
InputOption::VALUE_NONE, |
||||
'Number of MB to add to the max size of the course' |
||||
) |
||||
; |
||||
} |
||||
|
||||
/** |
||||
* @param InputInterface $input |
||||
* @param OutputInterface $output |
||||
* @return bool|int|null|void |
||||
*/ |
||||
protected function execute(InputInterface $input, OutputInterface $output) |
||||
{ |
||||
parent::execute($input, $output); |
||||
$add = $input->getOption('add-size'); //1 if the option was set |
||||
if (empty($add)) { |
||||
$add = 100; |
||||
} |
||||
$theshold = $input->getOption('threshold'); |
||||
if (empty($threshold)) { |
||||
$threshold = 75; |
||||
} |
||||
$this->writeCommandHeader($output, 'Checking courses dir...'); |
||||
|
||||
// Get database and path information |
||||
$coursesPath = $this->getConfigurationHelper()->getSysPath(); |
||||
$this->getConfigurationHelper()->getConnection(); |
||||
$_configuration = $this->getConfigurationHelper()->getConfiguration(); |
||||
|
||||
$courseTable = $_configuration['main_database'].'.course'; |
||||
$globalCourses = array(); |
||||
$sql = "SELECT c.id as cid, c.code as ccode, c.directory as cdir, c.disk_quota as cquota |
||||
FROM $courseTable c"; |
||||
$res = mysql_query($sql); |
||||
if ($res && mysql_num_rows($res) > 0) { |
||||
while ($row = mysql_fetch_assoc($res)) { |
||||
$globalCourses[$row['cdir']] = array('id' => $row['cid'], 'code' => $row['ccode'], 'quota' => $row['cquota']); |
||||
} |
||||
} |
||||
|
||||
$dirs = $this->getConfigurationHelper()->getDataFolders(1); |
||||
if (count($dirs) > 0) { |
||||
foreach ($dirs as $dir) { |
||||
$file = $dir->getFileName(); |
||||
$res = exec('du -s '.$dir->getRealPath()); // results are returned in KB (under Linux) |
||||
$res = preg_split('/\s/',$res); |
||||
$size = round($res[0]/1024,1); // $size is stored in MB |
||||
if (isset($globalCourses[$file]['code'])) { |
||||
$code = $globalCourses[$file]['code']; |
||||
$quota = round($globalCourses[$file]['quota']/(1024*1024), 0); //quota is originally in Bytes in DB. Store in MB |
||||
$rate = '-'; |
||||
if ($quota > 0) { |
||||
$newAllowedSize = $quota; |
||||
$rate = round(($size/$newAllowedSize)*100, 0); //rate is a percentage of disk use vs allowed quota, in MB |
||||
$increase = false; |
||||
while ($rate > $threshold) { // Typically 80 > 75 -> increase quota |
||||
//$output->writeln('...Rate '.$rate.' is larger than '.$threshold.', so increase allowed size'); |
||||
// Current disk usage goes beyond threshold. Increase allowed size by 100MB |
||||
$newAllowedSize += $add; |
||||
//$output->writeln('....New allowed size is '.$newAllowedSize); |
||||
$rate = round(($size/$newAllowedSize)*100, 0); |
||||
//$output->writeln('...Rate is now '.$rate); |
||||
$increase = true; |
||||
} |
||||
$newAllowedSize = $newAllowedSize*1024*1024; |
||||
//$output->writeln('Allowed size is '.$newAllowedSize.' Bytes, or '.round($newAllowedSize/(1024*1024))); |
||||
$sql = "UPDATE $courseTable SET disk_quota = $newAllowedSize WHERE id = ".$globalCourses[$file]['id']; |
||||
$res = mysql_query($sql); |
||||
if ($increase) { |
||||
$output->writeln('Increased max size of '.$globalCourses[$file]['code'].'('.$globalCourses[$file]['id'].') to '.$newAllowedSize); |
||||
} |
||||
} else { |
||||
//Quota is 0 (unlimited?) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
$output->writeln('Done increasing disk space'); |
||||
} |
||||
} |
||||
@ -0,0 +1,15 @@ |
||||
<?php |
||||
/** |
||||
* Created by JetBrains PhpStorm. |
||||
* User: ywarnier |
||||
* Date: 18/02/14 |
||||
* Time: 14:24 |
||||
* To change this template use File | Settings | File Templates. |
||||
*/ |
||||
|
||||
namespace Chash\Command\Files; |
||||
|
||||
|
||||
class UpdateDirectoryMaxSizeCommandTest extends \PHPUnit_Framework_TestCase { |
||||
|
||||
} |
||||
File diff suppressed because it is too large
Load Diff
@ -1 +1 @@ |
||||
4.5.0 |
||||
4.6.0 |
||||
@ -1,6 +1,5 @@ |
||||
HTML Purifier 4.5.0 is a minor bugfix and feature release, containing an |
||||
accumulation of changes over a year. CSS support has been extended to |
||||
support display:inline-block, white-space, underscores in font families, |
||||
page-break-* CSS3 properties (when proprietary is enabled.) We now use |
||||
SHA-1 to identify cached definitions, and the semantics of stacked |
||||
attribute transforms has changed slightly. |
||||
HTML Purifier 4.6.0 is a major security release, fixing numerous bad |
||||
quadratic asymptotics in HTML Purifier's core algorithms. Most users will |
||||
see a decent speedup on large inputs, although small inputs may take |
||||
longer. Additionally, the secure URI munging algorithm has changed to |
||||
do a proper HMAC. There are some other miscellaneous bugfixes as well. |
||||
|
||||
@ -0,0 +1,71 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Converts a stream of HTMLPurifier_Token into an HTMLPurifier_Node, |
||||
* and back again. |
||||
* |
||||
* @note This transformation is not an equivalence. We mutate the input |
||||
* token stream to make it so; see all [MUT] markers in code. |
||||
*/ |
||||
class HTMLPurifier_Arborize |
||||
{ |
||||
public static function arborize($tokens, $config, $context) { |
||||
$definition = $config->getHTMLDefinition(); |
||||
$parent = new HTMLPurifier_Token_Start($definition->info_parent); |
||||
$stack = array($parent->toNode()); |
||||
foreach ($tokens as $token) { |
||||
$token->skip = null; // [MUT] |
||||
$token->carryover = null; // [MUT] |
||||
if ($token instanceof HTMLPurifier_Token_End) { |
||||
$token->start = null; // [MUT] |
||||
$r = array_pop($stack); |
||||
assert($r->name === $token->name); |
||||
assert(empty($token->attr)); |
||||
$r->endCol = $token->col; |
||||
$r->endLine = $token->line; |
||||
$r->endArmor = $token->armor; |
||||
continue; |
||||
} |
||||
$node = $token->toNode(); |
||||
$stack[count($stack)-1]->children[] = $node; |
||||
if ($token instanceof HTMLPurifier_Token_Start) { |
||||
$stack[] = $node; |
||||
} |
||||
} |
||||
assert(count($stack) == 1); |
||||
return $stack[0]; |
||||
} |
||||
|
||||
public static function flatten($node, $config, $context) { |
||||
$level = 0; |
||||
$nodes = array($level => new HTMLPurifier_Queue(array($node))); |
||||
$closingTokens = array(); |
||||
$tokens = array(); |
||||
do { |
||||
while (!$nodes[$level]->isEmpty()) { |
||||
$node = $nodes[$level]->shift(); // FIFO |
||||
list($start, $end) = $node->toTokenPair(); |
||||
if ($level > 0) { |
||||
$tokens[] = $start; |
||||
} |
||||
if ($end !== NULL) { |
||||
$closingTokens[$level][] = $end; |
||||
} |
||||
if ($node instanceof HTMLPurifier_Node_Element) { |
||||
$level++; |
||||
$nodes[$level] = new HTMLPurifier_Queue(); |
||||
foreach ($node->children as $childNode) { |
||||
$nodes[$level]->push($childNode); |
||||
} |
||||
} |
||||
} |
||||
$level--; |
||||
if ($level && isset($closingTokens[$level])) { |
||||
while ($token = array_pop($closingTokens[$level])) { |
||||
$tokens[] = $token; |
||||
} |
||||
} |
||||
} while ($level > 0); |
||||
return $tokens; |
||||
} |
||||
} |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue