Merge branch 'MDL-41827_master' of git://github.com/dmonllao/moodle
Conflicts: admin/tool/generator/classes/site_backend.php
This commit is contained in:
@@ -51,6 +51,11 @@ abstract class tool_generator_backend {
|
||||
*/
|
||||
protected $fixeddataset;
|
||||
|
||||
/**
|
||||
* @var int|bool Maximum number of bytes for file.
|
||||
*/
|
||||
protected $filesizelimit;
|
||||
|
||||
/**
|
||||
* @var bool True if displaying progress
|
||||
*/
|
||||
@@ -81,10 +86,11 @@ abstract class tool_generator_backend {
|
||||
*
|
||||
* @param int $size Size as numeric index
|
||||
* @param bool $fixeddataset To use fixed or random data
|
||||
* @param int|bool $filesizelimit The max number of bytes for a generated file
|
||||
* @param bool $progress True if progress information should be displayed
|
||||
* @throws coding_exception If parameters are invalid
|
||||
*/
|
||||
public function __construct($size, $fixeddataset = false, $progress = true) {
|
||||
public function __construct($size, $fixeddataset = false, $filesizelimit = false, $progress = true) {
|
||||
|
||||
// Check parameter.
|
||||
if ($size < self::MIN_SIZE || $size > self::MAX_SIZE) {
|
||||
@@ -94,6 +100,7 @@ abstract class tool_generator_backend {
|
||||
// Set parameters.
|
||||
$this->size = $size;
|
||||
$this->fixeddataset = $fixeddataset;
|
||||
$this->filesizelimit = $filesizelimit;
|
||||
$this->progress = $progress;
|
||||
}
|
||||
|
||||
|
||||
@@ -100,15 +100,15 @@ class tool_generator_course_backend extends tool_generator_backend {
|
||||
* @param string $shortname Course shortname
|
||||
* @param int $size Size as numeric index
|
||||
* @param bool $fixeddataset To use fixed or random data
|
||||
* @param int|bool $filesizelimit The max number of bytes for a generated file
|
||||
* @param bool $progress True if progress information should be displayed
|
||||
* @return int Course id
|
||||
*/
|
||||
public function __construct($shortname, $size, $fixeddataset = false, $progress = true) {
|
||||
public function __construct($shortname, $size, $fixeddataset = false, $filesizelimit = false, $progress = true) {
|
||||
|
||||
// Set parameters.
|
||||
$this->shortname = $shortname;
|
||||
|
||||
parent::__construct($size, $fixeddataset, $progress);
|
||||
parent::__construct($size, $fixeddataset, $filesizelimit, $progress);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -345,7 +345,7 @@ class tool_generator_course_backend extends tool_generator_backend {
|
||||
|
||||
// Generate random binary data (different for each file so it
|
||||
// doesn't compress unrealistically).
|
||||
$data = self::get_random_binary(self::$paramsmallfilesize[$this->size]);
|
||||
$data = self::get_random_binary($this->limit_filesize(self::$paramsmallfilesize[$this->size]));
|
||||
|
||||
$fs->create_file_from_string($filerecord, $data);
|
||||
$this->dot($i, $count);
|
||||
@@ -362,6 +362,7 @@ class tool_generator_course_backend extends tool_generator_backend {
|
||||
* @return Random data
|
||||
*/
|
||||
private static function get_random_binary($length) {
|
||||
|
||||
$data = microtime(true);
|
||||
if (strlen($data) > $length) {
|
||||
// Use last digits of data.
|
||||
@@ -382,8 +383,9 @@ class tool_generator_course_backend extends tool_generator_backend {
|
||||
|
||||
// Work out how many files and how many blocks to use (up to 64KB).
|
||||
$count = self::$parambigfilecount[$this->size];
|
||||
$blocks = ceil(self::$parambigfilesize[$this->size] / 65536);
|
||||
$blocksize = floor(self::$parambigfilesize[$this->size] / $blocks);
|
||||
$filesize = $this->limit_filesize(self::$parambigfilesize[$this->size]);
|
||||
$blocks = ceil($filesize / 65536);
|
||||
$blocksize = floor($filesize / $blocks);
|
||||
|
||||
$this->log('createbigfiles', $count, true);
|
||||
|
||||
@@ -504,4 +506,20 @@ class tool_generator_course_backend extends tool_generator_backend {
|
||||
return $userid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restricts the binary file size if necessary
|
||||
*
|
||||
* @param int $length The total length
|
||||
* @return int The limited length if a limit was specified.
|
||||
*/
|
||||
private function limit_filesize($length) {
|
||||
|
||||
// Limit to $this->filesizelimit.
|
||||
if (is_numeric($this->filesizelimit) && $length > $this->filesizelimit) {
|
||||
$length = floor($this->filesizelimit);
|
||||
}
|
||||
|
||||
return $length;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -61,15 +61,16 @@ class tool_generator_site_backend extends tool_generator_backend {
|
||||
* @param int $size Size as numeric index
|
||||
* @param bool $bypasscheck If debugging level checking was skipped.
|
||||
* @param bool $fixeddataset To use fixed or random data
|
||||
* @param int|bool $filesizelimit The max number of bytes for a generated file
|
||||
* @param bool $progress True if progress information should be displayed
|
||||
* @return int Course id
|
||||
*/
|
||||
public function __construct($size, $bypasscheck, $fixeddataset = false, $progress = true) {
|
||||
public function __construct($size, $bypasscheck, $fixeddataset = false, $filesizelimit = false, $progress = true) {
|
||||
|
||||
// Set parameters.
|
||||
$this->bypasscheck = $bypasscheck;
|
||||
|
||||
parent::__construct($size, $fixeddataset, $progress);
|
||||
parent::__construct($size, $fixeddataset, $filesizelimit, $progress);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,6 +149,10 @@ class tool_generator_site_backend extends tool_generator_backend {
|
||||
$options[] = '--quiet';
|
||||
}
|
||||
|
||||
if ($this->filesizelimit) {
|
||||
$options[] = '--filesizelimit="' . $this->filesizelimit . '"';
|
||||
}
|
||||
|
||||
// Extend options.
|
||||
$optionstoextend = array(
|
||||
'fixeddataset' => 'fixeddataset',
|
||||
|
||||
Reference in New Issue
Block a user