Permalink
Browse files

Merge branch 'MOODLE_25_STABLE' into install_25_STABLE

  • Loading branch information...
2 parents 976d7e3 + 0bd9f00 commit 2fc1329f4486b3465f086ff8a4d1f9a724a25471 AMOS bot committed Aug 31, 2013
Showing with 576 additions and 226 deletions.
  1. +8 −2 backup/util/loggers/database_logger.class.php
  2. +1 −1 backup/util/structure/tests/baseoptiogroup_test.php
  3. +1 −1 backup/util/ui/renderer.php
  4. +189 −144 cache/classes/loaders.php
  5. +7 −11 cache/stores/file/lib.php
  6. +1 −1 cache/stores/memcache/lib.php
  7. +1 −0 cache/stores/memcached/lib.php
  8. +64 −7 cache/stores/session/lib.php
  9. +90 −3 cache/tests/cache_test.php
  10. +18 −0 cache/tests/fixtures/lib.php
  11. +29 −9 course/manage.php
  12. +3 −0 lang/en/backup.php
  13. +1 −1 lang/en/tag.php
  14. +15 −0 lib/editor/tinymce/module.js
  15. +1 −1 lib/editor/tinymce/version.php
  16. +2 −0 lib/form/filemanager.js
  17. +5 −9 lib/modinfolib.php
  18. +11 −0 lib/tests/textlib_test.php
  19. +30 −0 lib/textlib.class.php
  20. +1 −0 mod/assign/backup/moodle2/restore_assign_stepslib.php
  21. +2 −10 mod/quiz/renderer.php
  22. +6 −0 mod/quiz/upgrade.txt
  23. +7 −1 mod/wiki/pagelib.php
  24. +1 −1 question/behaviour/informationitem/lang/en/qbehaviour_informationitem.php
  25. +2 −0 repository/filepicker.js
  26. +17 −11 repository/url/locallib.php
  27. +4 −0 theme/base/style/core.css
  28. +3 −0 theme/bootstrapbase/less/moodle.less
  29. +13 −0 theme/bootstrapbase/less/moodle/bootstrapoverride.less
  30. +1 −0 theme/bootstrapbase/less/moodle/core.less
  31. +10 −0 theme/bootstrapbase/less/moodle/filemanager.less
  32. +26 −7 theme/bootstrapbase/less/moodle/forms.less
  33. +1 −1 theme/bootstrapbase/less/moodle/user.less
  34. +2 −2 theme/bootstrapbase/style/moodle.css
  35. +1 −1 user/filters/lib.php
  36. +2 −2 version.php
@@ -59,7 +59,13 @@ protected function action($message, $level, $options = null) {
if ($this->levelcol) {
$columns[$this->levelcol] = $level;
}
- $columns[$this->messagecol] = $message; //TODO: should this be cleaned?
+ $message = clean_param($message, PARAM_NOTAGS);
+ // Check if the message exceeds the 255 character limit in the database,
+ // if it does, shorten it so that it can be inserted successfully.
+ if (textlib::strlen($message) > 255) {
+ $message = textlib::substr($message, 0, 252) . '...';
+ }
+ $columns[$this->messagecol] = $message;
return $this->insert_log_record($this->logtable, $columns);
}
@@ -69,6 +75,6 @@ protected function insert_log_record($table, $columns) {
// to preserve DB logs if the whole backup/restore transaction is
// rollback
global $DB;
- return $DB->insert_record($this->logtable, $columns, false); // Don't return inserted id
+ return $DB->insert_record($table, $columns, false); // Don't return inserted id
}
}
@@ -69,7 +69,7 @@ function test_creation() {
/**
* Incorrect creation tests (attributes and final elements)
*/
- function itest_wrong_creation() {
+ function test_wrong_creation() {
// Create instance with invalid name
try {
@@ -140,7 +140,7 @@ public function backup_details($details, $nextstageurl) {
}
if (empty($table)) {
$table = new html_table();
- $table->head = array('Module', 'Title', 'Userinfo');
+ $table->head = array(get_string('module','backup'), get_string('title','backup'), get_string('userinfo','backup'));
$table->colclasses = array('modulename', 'moduletitle', 'userinfoincluded');
$table->align = array('left','left', 'center');
$table->attributes = array('class'=>'activitytable generaltable');
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -353,23 +353,19 @@ public function get($key) {
if (!$readfile) {
return false;
}
- // Check the filesize first, likely not needed but important none the less.
- $filesize = filesize($file);
- if (!$filesize) {
- return false;
- }
- // Open ensuring the file for writing, truncating it and setting the pointer to the start.
+ // Open ensuring the file for reading in binary format.
if (!$handle = fopen($file, 'rb')) {
return false;
}
// Lock it up!
// We don't care if this succeeds or not, on some systems it will, on some it won't, meah either way.
flock($handle, LOCK_SH);
- // HACK ALERT
- // There is a problem when reading from the file during PHPUNIT tests. For one reason or another the filesize is not correct
- // Doesn't happen during normal operation, just during unit tests.
- // Read it.
- $data = fread($handle, $filesize+128);
+ $data = '';
+ // Read the data in 1Mb chunks. Small caches will not loop more than once. We don't use filesize as it may
+ // be cached with a different value than what we need to read from the file.
+ do {
+ $data .= fread($handle, 1048576);
+ } while (!feof($handle));
// Unlock it.
flock($handle, LOCK_UN);
// Return it unserialised.
@@ -132,8 +132,8 @@ public function __construct($name, array $configuration = array()) {
$this->connection = new Memcache;
foreach ($this->servers as $server) {
$this->connection->addServer($server[0], $server[1], true, $server[2]);
- // Test the connection to this server.
}
+ // Test the connection to the pool of servers.
$this->isready = @$this->connection->set($this->parse_key('ping'), 'ping', MEMCACHE_COMPRESSED, 1);
}
@@ -141,6 +141,7 @@ public function __construct($name, array $configuration = array()) {
}
$this->connection->addServers($this->servers);
}
+ // Test the connection to the pool of servers.
$this->isready = @$this->connection->set("ping", 'ping', 1);
}
@@ -190,8 +190,9 @@ public static function is_supported_mode($mode) {
*/
public function initialise(cache_definition $definition) {
$this->storeid = $definition->generate_definition_hash();
- $this->store = &self::register_store_id($definition->get_id());
+ $this->store = &self::register_store_id($this->name.'-'.$definition->get_id());
$this->ttl = $definition->get_ttl();
+ $this->check_ttl();
}
/**
@@ -219,10 +220,13 @@ public function is_ready() {
*/
public function get($key) {
if (isset($this->store[$key])) {
- if ($this->ttl == 0) {
+ if ($this->ttl === 0) {
return $this->store[$key][0];
} else if ($this->store[$key][1] >= (cache::now() - $this->ttl)) {
return $this->store[$key][0];
+ } else {
+ // Element is present but has expired.
+ $this->check_ttl();
}
}
return false;
@@ -239,20 +243,28 @@ public function get($key) {
*/
public function get_many($keys) {
$return = array();
+ $maxtime = 0;
if ($this->ttl != 0) {
$maxtime = cache::now() - $this->ttl;
}
+ $hasexpiredelements = false;
foreach ($keys as $key) {
$return[$key] = false;
if (isset($this->store[$key])) {
if ($this->ttl == 0) {
$return[$key] = $this->store[$key][0];
} else if ($this->store[$key][1] >= $maxtime) {
$return[$key] = $this->store[$key][0];
+ } else {
+ $hasexpiredelements = true;
}
}
}
+ if ($hasexpiredelements) {
+ // There are some elements that are present but have expired.
+ $this->check_ttl();
+ }
return $return;
}
@@ -264,8 +276,8 @@ public function get_many($keys) {
* @return bool True if the operation was a success false otherwise.
*/
public function set($key, $data) {
- if ($this->ttl == 0) {
- $this->store[$key][0] = $data;
+ if ($this->ttl === 0) {
+ $this->store[$key] = array($data, 0);
} else {
$this->store[$key] = array($data, cache::now());
}
@@ -283,8 +295,14 @@ public function set($key, $data) {
public function set_many(array $keyvaluearray) {
$count = 0;
foreach ($keyvaluearray as $pair) {
- $this->set($pair['key'], $pair['value']);
+ $key = $pair['key'];
+ $data = $pair['value'];
$count++;
+ if ($this->ttl === 0) {
+ $this->store[$key] = array($data, 0);
+ } else {
+ $this->store[$key] = array($data, cache::now());
+ }
}
return $count;
}
@@ -313,6 +331,7 @@ public function has($key) {
* @return bool
*/
public function has_all(array $keys) {
+ $maxtime = 0;
if ($this->ttl != 0) {
$maxtime = cache::now() - $this->ttl;
}
@@ -335,6 +354,7 @@ public function has_all(array $keys) {
* @return bool
*/
public function has_any(array $keys) {
+ $maxtime = 0;
if ($this->ttl != 0) {
$maxtime = cache::now() - $this->ttl;
}
@@ -354,9 +374,11 @@ public function has_any(array $keys) {
* @return bool Returns true if the operation was a success, false otherwise.
*/
public function delete($key) {
- $result = isset($this->store[$key]);
+ if (!isset($this->store[$key])) {
+ return false;
+ }
unset($this->store[$key]);
- return $result;
+ return true;
}
/**
@@ -366,6 +388,7 @@ public function delete($key) {
* @return int The number of items successfully deleted.
*/
public function delete_many(array $keys) {
+ // The number of items that have been successfully deleted.
$count = 0;
foreach ($keys as $key) {
if (isset($this->store[$key])) {
@@ -424,18 +447,44 @@ public function my_name() {
}
/**
+ * Removes expired elements.
+ * @return int number of removed elements
+ */
+ protected function check_ttl() {
+ if ($this->ttl === 0) {
+ return 0;
+ }
+ $maxtime = cache::now() - $this->ttl;
+ $count = 0;
+ for ($value = reset($this->store); $value !== false; $value = next($this->store)) {
+ if ($value[1] >= $maxtime) {
+ // We know that elements are sorted by ttl so no need to continue.
+ break;
+ }
+ $count++;
+ }
+ if ($count) {
+ // Remove first $count elements as they are expired.
+ $this->store = array_slice($this->store, $count, null, true);
+ }
+ return $count;
+ }
+
+ /**
* Finds all of the keys being stored in the cache store instance.
*
* @return array
*/
public function find_all() {
+ $this->check_ttl();
return array_keys($this->store);
}
/**
* Finds all of the keys whose keys start with the given prefix.
*
* @param string $prefix
+ * @return array An array of keys.
*/
public function find_by_prefix($prefix) {
$return = array();
@@ -446,4 +495,12 @@ public function find_by_prefix($prefix) {
}
return $return;
}
+
+ /**
+ * This store supports native TTL handling.
+ * @return bool
+ */
+ public function store_supports_native_ttl() {
+ return true;
+ }
}
View
@@ -1126,9 +1126,9 @@ public function test_disable() {
}
/**
- * Test that multiple loaders work ok.
+ * Test that multiple application loaders work ok.
*/
- public function test_multiple_loaders() {
+ public function test_multiple_application_loaders() {
$instance = cache_config_phpunittest::instance(true);
$instance->phpunit_add_file_store('phpunittest1');
$instance->phpunit_add_file_store('phpunittest2');
@@ -1173,6 +1173,93 @@ public function test_multiple_loaders() {
$this->assertFalse($result['a']);
$this->assertEquals('B', $result['b']);
$this->assertFalse($result['c']);
+
+ // Test non-recursive deletes.
+ $this->assertTrue($cache->set('test', 'test'));
+ $this->assertSame('test', $cache->get('test'));
+ $this->assertTrue($cache->delete('test', false));
+ // We should still have it on a deeper loader.
+ $this->assertSame('test', $cache->get('test'));
+ // Test non-recusive with many functions.
+ $this->assertSame(3, $cache->set_many(array(
+ 'one' => 'one',
+ 'two' => 'two',
+ 'three' => 'three'
+ )));
+ $this->assertSame('one', $cache->get('one'));
+ $this->assertSame(array('two' => 'two', 'three' => 'three'), $cache->get_many(array('two', 'three')));
+ $this->assertSame(3, $cache->delete_many(array('one', 'two', 'three'), false));
+ $this->assertSame('one', $cache->get('one'));
+ $this->assertSame(array('two' => 'two', 'three' => 'three'), $cache->get_many(array('two', 'three')));
+ }
+
+ /**
+ * Test that multiple application loaders work ok.
+ */
+ public function test_multiple_session_loaders() {
+ /* @var cache_config_phpunittest $instance */
+ $instance = cache_config_phpunittest::instance(true);
+ $instance->phpunit_add_session_store('phpunittest1');
+ $instance->phpunit_add_session_store('phpunittest2');
+ $instance->phpunit_add_definition('phpunit/multi_loader', array(
+ 'mode' => cache_store::MODE_SESSION,
+ 'component' => 'phpunit',
+ 'area' => 'multi_loader'
+ ));
+ $instance->phpunit_add_definition_mapping('phpunit/multi_loader', 'phpunittest1', 3);
+ $instance->phpunit_add_definition_mapping('phpunit/multi_loader', 'phpunittest2', 2);
+
+ $cache = cache::make('phpunit', 'multi_loader');
+ $this->assertInstanceOf('cache_session', $cache);
+ $this->assertFalse($cache->get('test'));
+ $this->assertTrue($cache->set('test', 'test'));
+ $this->assertEquals('test', $cache->get('test'));
+ $this->assertTrue($cache->delete('test'));
+ $this->assertFalse($cache->get('test'));
+ $this->assertTrue($cache->set('test', 'test'));
+ $this->assertTrue($cache->purge());
+ $this->assertFalse($cache->get('test'));
+
+ // Test the many commands.
+ $this->assertEquals(3, $cache->set_many(array('a' => 'A', 'b' => 'B', 'c' => 'C')));
+ $result = $cache->get_many(array('a', 'b', 'c'));
+ $this->assertInternalType('array', $result);
+ $this->assertCount(3, $result);
+ $this->assertArrayHasKey('a', $result);
+ $this->assertArrayHasKey('b', $result);
+ $this->assertArrayHasKey('c', $result);
+ $this->assertEquals('A', $result['a']);
+ $this->assertEquals('B', $result['b']);
+ $this->assertEquals('C', $result['c']);
+ $this->assertEquals($result, $cache->get_many(array('a', 'b', 'c')));
+ $this->assertEquals(2, $cache->delete_many(array('a', 'c')));
+ $result = $cache->get_many(array('a', 'b', 'c'));
+ $this->assertInternalType('array', $result);
+ $this->assertCount(3, $result);
+ $this->assertArrayHasKey('a', $result);
+ $this->assertArrayHasKey('b', $result);
+ $this->assertArrayHasKey('c', $result);
+ $this->assertFalse($result['a']);
+ $this->assertEquals('B', $result['b']);
+ $this->assertFalse($result['c']);
+
+ // Test non-recursive deletes.
+ $this->assertTrue($cache->set('test', 'test'));
+ $this->assertSame('test', $cache->get('test'));
+ $this->assertTrue($cache->delete('test', false));
+ // We should still have it on a deeper loader.
+ $this->assertSame('test', $cache->get('test'));
+ // Test non-recusive with many functions.
+ $this->assertSame(3, $cache->set_many(array(
+ 'one' => 'one',
+ 'two' => 'two',
+ 'three' => 'three'
+ )));
+ $this->assertSame('one', $cache->get('one'));
+ $this->assertSame(array('two' => 'two', 'three' => 'three'), $cache->get_many(array('two', 'three')));
+ $this->assertSame(3, $cache->delete_many(array('one', 'two', 'three'), false));
+ $this->assertSame('one', $cache->get('one'));
+ $this->assertSame(array('two' => 'two', 'three' => 'three'), $cache->get_many(array('two', 'three')));
}
/**
@@ -1448,4 +1535,4 @@ public function test_defaults_support_searching() {
$this->assertInstanceOf('cache_request', $cache);
$this->assertArrayHasKey('cache_is_searchable', $cache->phpunit_get_store_implements());
}
-}
+}
Oops, something went wrong.

0 comments on commit 2fc1329

Please sign in to comment.