Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of https://github.com/moodle/moodle

  • Loading branch information...
commit a96cbb5162d943f8faaa318ebd7793f63b1e9f5b 2 parents 5c631d8 + 668a499
@doraemonyoung doraemonyoung authored
Showing with 21,991 additions and 599 deletions.
  1. +22 −0 admin/tool/phpunit/cli/init.bat
  2. +66 −0 admin/tool/phpunit/cli/init.php
  3. +31 −0 admin/tool/phpunit/cli/init.sh
  4. +84 −14 admin/tool/phpunit/cli/util.php
  5. +1 −3 admin/tool/phpunit/index.php
  6. +5 −1 admin/tool/phpunit/settings.php
  7. +2 −2 admin/tool/phpunit/version.php
  8. +192 −0 admin/tool/phpunit/webrunner.php
  9. +5 −0 backup/moodle2/backup_activity_task.class.php
  10. +5 −0 backup/moodle2/backup_course_task.class.php
  11. +6 −0 backup/moodle2/backup_root_task.class.php
  12. +7 −0 backup/moodle2/backup_settingslib.php
  13. +42 −0 backup/moodle2/backup_stepslib.php
  14. +5 −0 backup/moodle2/restore_activity_task.class.php
  15. +5 −0 backup/moodle2/restore_course_task.class.php
  16. +13 −0 backup/moodle2/restore_root_task.class.php
  17. +7 −0 backup/moodle2/restore_settingslib.php
  18. +70 −0 backup/moodle2/restore_stepslib.php
  19. +1 −1  backup/util/factories/tests/factories_test.php
  20. +2 −0  backup/util/loggers/simpletest/testlogger.php
  21. +3 −0  backup/util/loggers/tests/logger_test.php
  22. +63 −0 blocks/online_users/tests/generator/lib.php
  23. +57 −0 blocks/online_users/tests/generator_test.php
  24. +10 −3 blog/locallib.php
  25. +16 −9 blog/tests/bloglib_test.php
  26. +0 −6 config-dist.php
  27. +3 −3 index.php
  28. +6 −6 install/lang/de/error.php
  29. +35 −0 install/lang/de_comm/langconfig.php
  30. +1 −0  lang/en/backup.php
  31. +10 −3 lang/en/question.php
  32. +1 −1  lib/clilib.php
  33. +4 −3 lib/cronlib.php
  34. +12 −2 lib/ddl/mssql_sql_generator.php
  35. +8 −1 lib/ddl/simpletest/testddl.php
  36. +11 −4 lib/ddl/tests/ddl_test.php
  37. +0 −1  lib/dml/database_column_info.php
  38. +5 −1 lib/dml/moodle_database.php
  39. +33 −14 lib/dml/mssql_native_moodle_database.php
  40. +1 −2  lib/dml/mysqli_native_moodle_database.php
  41. +13 −8 lib/dml/oci_native_moodle_database.php
  42. +15 −2 lib/dml/pgsql_native_moodle_database.php
  43. +26 −0 lib/dml/simpletest/testdml.php
  44. +29 −13 lib/dml/sqlsrv_native_moodle_database.php
  45. +32 −1 lib/dml/tests/dml_test.php
  46. +4 −7 lib/enrollib.php
  47. +773 −0 lib/grade/tests/fixtures/lib.php
  48. +646 −0 lib/grade/tests/grade_category_test.php
  49. +196 −0 lib/grade/tests/grade_grade_test.php
  50. +547 −0 lib/grade/tests/grade_item_test.php
  51. +106 −0 lib/grade/tests/grade_outcome_test.php
  52. +130 −0 lib/grade/tests/grade_scale_test.php
  53. +0 −41 lib/moodlelib.php
  54. +1 −1  lib/navigationlib.php
  55. +6 −0 lib/outputlib.php
  56. +48 −69 lib/phpunit/bootstrap.php
  57. +106 −0 lib/phpunit/bootstraplib.php
  58. +281 −107 lib/phpunit/generatorlib.php
  59. +662 −159 lib/phpunit/lib.php
  60. +248 −0 lib/phpunit/phpunit.xsd
  61. +13 −34 lib/phpunit/readme.md
  62. +3 −1 lib/setup.php
  63. +1 −1  lib/setuplib.php
  64. +3 −0  lib/tests/fixtures/sample_dataset.csv
  65. +18 −0 lib/tests/fixtures/sample_dataset.xml
  66. +271 −0 lib/tests/phpunit_test.php
  67. +42 −0 lib/upgradelib.php
  68. +81 −0 mod/assignment/tests/generator/lib.php
  69. +63 −0 mod/assignment/tests/generator_test.php
  70. +2,001 −0 mod/data/tests/fixtures/test_data_content.csv
  71. +21 −0 mod/data/tests/fixtures/test_data_fields.csv
  72. +101 −0 mod/data/tests/fixtures/test_data_records.csv
  73. +74 −0 mod/data/tests/generator/lib.php
  74. +63 −0 mod/data/tests/generator_test.php
  75. +197 −0 mod/data/tests/search_test.php
  76. +23 −6 mod/feedback/show_nonrespondents.php
  77. +75 −0 mod/forum/tests/generator/lib.php
  78. +63 −0 mod/forum/tests/generator_test.php
  79. +84 −0 mod/page/tests/generator/lib.php
  80. +63 −0 mod/page/tests/generator_test.php
  81. +1 −1  mod/quiz/accessrule/delaybetweenattempts/rule.php
  82. +3 −3 mod/quiz/editlib.php
  83. +13 −2 mod/quiz/lang/en/quiz.php
  84. +20 −10 mod/quiz/mod_form.php
  85. +1 −1  mod/quiz/report/grading/gradingsettings_form.php
  86. +1 −0  mod/quiz/report/grading/lang/en/quiz_grading.php
  87. +14 −8 mod/quiz/report/grading/report.php
  88. +1 −1  mod/quiz/report/overview/overview_table.php
  89. +1 −1  mod/quiz/report/overview/report.php
  90. +1 −1  mod/quiz/report/responses/report.php
  91. +1 −1  mod/quiz/report/responses/responses_table.php
  92. +2 −2 mod/quiz/report/statistics/report.php
  93. +1 −1  mod/quiz/report/statistics/statistics_question_table.php
  94. +1 −1  mod/quiz/report/statistics/statistics_table.php
  95. +14 −25 mod/quiz/styles.css
  96. +15 −7 phpunit.xml.dist
  97. +747 −0 question/behaviour/adaptive/tests/walkthrough_test.php
  98. +292 −0 question/behaviour/adaptivenopenalty/tests/walkthrough_test.php
  99. +273 −0 question/behaviour/deferredcbm/tests/walkthrough_test.php
  100. +214 −0 question/behaviour/deferredfeedback/tests/walkthrough_test.php
  101. +292 −0 question/behaviour/immediatecbm/tests/walkthrough_test.php
  102. +246 −0 question/behaviour/immediatefeedback/tests/walkthrough_test.php
  103. +88 −0 question/behaviour/informationitem/tests/walkthrough_test.php
  104. +490 −0 question/behaviour/interactive/tests/walkthrough_test.php
  105. +149 −0 question/behaviour/interactivecountback/tests/walkthrough_test.php
  106. +270 −0 question/behaviour/manualgraded/tests/walkthrough_test.php
  107. +109 −0 question/behaviour/missing/tests/missingbehaviour_test.php
  108. +2 −2 question/engine/questionusage.php
  109. +161 −0 question/engine/tests/datalib_test.php
  110. +1,009 −0 question/engine/tests/helpers.php
  111. +373 −0 question/engine/tests/questionattempt_test.php
  112. +117 −0 question/engine/tests/questionattemptiterator_test.php
  113. +184 −0 question/engine/tests/questionattemptstep_test.php
  114. +136 −0 question/engine/tests/questionattemptstepiterator_test.php
  115. +86 −0 question/engine/tests/questionbank_test.php
  116. +48 −0 question/engine/tests/questioncbm_test.php
  117. +94 −0 question/engine/tests/questionengine_test.php
  118. +162 −0 question/engine/tests/questionstate_test.php
  119. +224 −0 question/engine/tests/questionusagebyactivity_test.php
  120. +194 −0 question/engine/tests/questionutils_test.php
  121. +302 −0 question/engine/tests/unitofwork_test.php
  122. +146 −0 question/engine/upgrade/tests/helper.php
  123. +2 −2 question/engine/upgrade/upgradelib.php
  124. +48 −0 question/format/gift/tests/fixtures/questions.gift.txt
  125. +888 −0 question/format/gift/tests/giftformat_test.php
  126. +1,409 −0 question/format/xml/tests/xmlformat_test.php
  127. +90 −0 question/tests/importexport_test.php
  128. +158 −0 question/type/calculated/tests/helper.php
  129. +152 −0 question/type/calculated/tests/question_test.php
  130. +109 −0 question/type/calculated/tests/questiontype_test.php
  131. +701 −0 question/type/calculated/tests/upgradelibnewqe_test.php
  132. +118 −0 question/type/calculated/tests/variablesubstituter_test.php
  133. +106 −0 question/type/calculated/tests/walkthrough_test.php
  134. +75 −0 question/type/calculatedmulti/tests/helper.php
  135. +114 −0 question/type/calculatedmulti/tests/question_test.php
  136. +803 −0 question/type/calculatedmulti/tests/upgradelibnewqe_test.php
  137. +106 −0 question/type/calculatedmulti/tests/walkthrough_test.php
  138. +80 −0 question/type/calculatedsimple/tests/helper.php
  139. +114 −0 question/type/calculatedsimple/tests/question_test.php
  140. +638 −0 question/type/calculatedsimple/tests/upgradelibnewqe_test.php
  141. +105 −0 question/type/calculatedsimple/tests/walkthrough_test.php
  142. +93 −0 question/type/description/tests/helper.php
  143. +69 −0 question/type/description/tests/questiontype_test.php
  144. +461 −0 question/type/description/tests/upgradelibnewqe_test.php
  145. +53 −0 question/type/description/tests/walkthrough_test.php
  146. +3 −0  question/type/edit_question_form.php
  147. +2 −0  question/type/essay/questiontype.php
  148. +52 −0 question/type/essay/tests/question_test.php
  149. +75 −0 question/type/essay/tests/questiontype_test.php
  150. +567 −0 question/type/essay/tests/upgradelibnewqe_test.php
  151. +184 −0 question/type/match/tests/question_test.php
  152. +139 −0 question/type/match/tests/questiontype_test.php
Sorry, we could not display the entire diff because it was too big.
View
22 admin/tool/phpunit/cli/init.bat
@@ -0,0 +1,22 @@
+@ECHO OFF
+ECHO Initialising Moodle PHPUnit test environment...
+
+CALL php %~dp0\util.php --diag > NUL 2>&1
+
+IF ERRORLEVEL 133 GOTO drop
+IF ERRORLEVEL 132 GOTO install
+IF ERRORLEVEL 1 GOTO unknown
+GOTO done
+
+:drop
+CALL php %~dp0\util.php --drop
+IF ERRORLEVEL 1 GOTO done
+
+:install
+CALL php %~dp0\util.php --install
+GOTO done
+
+:unknown
+CALL php %~dp0\util.php --diag
+
+:done
View
66 admin/tool/phpunit/cli/init.php
@@ -0,0 +1,66 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * All in one init script - PHP version.
+ *
+ * @package tool_phpunit
+ * @copyright 2012 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+if (isset($_SERVER['REMOTE_ADDR'])) {
+ die; // no access from web!
+}
+
+require_once(__DIR__.'/../../../../lib/clilib.php');
+require_once(__DIR__.'/../../../../lib/phpunit/bootstraplib.php');
+
+echo "Initialising Moodle PHPUnit test environment...\n";
+
+$output = null;
+exec('php --version', $output, $code);
+if ($code != 0) {
+ phpunit_bootstrap_error(1, 'Can not execute \'php\' binary.');
+}
+
+chdir(__DIR__);
+$output = null;
+exec("php util.php --diag", $output, $code);
+if ($code == 0) {
+ // everything is ready
+
+} else if ($code == 132) {
+ passthru("php util.php --install", $code);
+ if ($code != 0) {
+ exit($code);
+ }
+
+} else if ($code == 133) {
+ passthru("php util.php --drop", $code);
+ passthru("php util.php --install", $code);
+ if ($code != 0) {
+ exit($code);
+ }
+
+} else {
+ echo implode("\n", $output)."\n";
+ exit($code);
+}
+
+passthru("php util.php --buildconfig", $code);
+
+exit(0);
View
31 admin/tool/phpunit/cli/init.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+SOURCE="${BASH_SOURCE[0]}"
+while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
+CLIDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+
+UTIL="$CLIDIR/util.php"
+
+echo "Initialising Moodle PHPUnit test environment..."
+
+DIGERROR=`php $UTIL --diag`
+DIAG=$?
+if [ $DIAG -eq 132 ] ; then
+ php $UTIL --install
+else
+ if [ $DIAG -eq 133 ] ; then
+ php $UTIL --drop
+ RESULT=$?
+ if [ $RESULT -gt 0 ] ; then
+ exit $RESULT
+ fi
+ php $UTIL --install
+ else
+ if [ $DIAG -gt 0 ] ; then
+ echo $DIGERROR
+ exit $DIAG
+ fi
+ fi
+fi
+
+php $UTIL --buildconfig
View
98 admin/tool/phpunit/cli/util.php
@@ -20,24 +20,23 @@
* Exit codes:
* 0 - success
* 1 - general error
- * 130 - coding error
+ * 130 - missing PHPUnit library error
* 131 - configuration problem
+ * 132 - install new test database
* 133 - drop existing data before installing
+ * 134 - can not create main phpunit.xml
*
* @package tool_phpunit
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-define('PHPUNIT_UTIL', true);
+if (isset($_SERVER['REMOTE_ADDR'])) {
+ die; // no access from web!
+}
-require(__DIR__ . '/../../../../lib/phpunit/bootstrap.php');
-require_once($CFG->libdir.'/phpunit/lib.php');
-require_once($CFG->libdir.'/adminlib.php');
-require_once($CFG->libdir.'/upgradelib.php');
-require_once($CFG->libdir.'/clilib.php');
-require_once($CFG->libdir.'/pluginlib.php');
-require_once($CFG->libdir.'/installlib.php');
+require_once(__DIR__.'/../../../../lib/clilib.php');
+require_once(__DIR__.'/../../../../lib/phpunit/bootstraplib.php');
// now get cli options
list($options, $unrecognized) = cli_get_params(
@@ -45,6 +44,9 @@
'drop' => false,
'install' => false,
'buildconfig' => false,
+ 'diag' => false,
+ 'phpunitdir' => false,
+ 'run' => false,
'help' => false,
),
array(
@@ -52,37 +54,105 @@
)
);
+if ($options['phpunitdir']) {
+ // nasty skodak's hack for testing of future PHPUnit versions - intentionally not documented
+ if (!file_exists($options['phpunitdir'])) {
+ cli_error('Invalid custom PHPUnit lib location');
+ }
+ $files = scandir($options['phpunitdir']);
+ foreach ($files as $file) {
+ $path = $options['phpunitdir'].'/'.$file;
+ if (!is_dir($path) or strpos($file, '.') === 0) {
+ continue;
+ }
+ ini_set('include_path', $path . PATH_SEPARATOR . ini_get('include_path'));
+ }
+ unset($files);
+ unset($file);
+}
+
+// verify PHPUnit libs are loaded
+if (!@include_once('PHPUnit/Autoload.php')) {
+ phpunit_bootstrap_error(130);
+}
+
+if (!@include_once('PHPUnit/Extensions/Database/Autoload.php')) {
+ phpunit_bootstrap_error(130);
+}
+
+if ($options['run']) {
+ unset($options);
+ unset($unrecognized);
+
+ foreach ($_SERVER['argv'] as $k=>$v) {
+ if (strpos($v, '--run') === 0 or strpos($v, '--phpunitdir') === 0) {
+ unset($_SERVER['argv'][$k]);
+ $_SERVER['argc'] = $_SERVER['argc'] - 1;
+ }
+ }
+ $_SERVER['argv'] = array_values($_SERVER['argv']);
+ PHPUnit_TextUI_Command::main();
+ exit(0);
+}
+
+define('PHPUNIT_UTIL', true);
+
+require(__DIR__ . '/../../../../lib/phpunit/bootstrap.php');
+
+// from now on this is a regular moodle CLI_SCRIPT
+
+require_once($CFG->libdir.'/adminlib.php');
+require_once($CFG->libdir.'/upgradelib.php');
+require_once($CFG->libdir.'/clilib.php');
+require_once($CFG->libdir.'/pluginlib.php');
+require_once($CFG->libdir.'/installlib.php');
+
if ($unrecognized) {
$unrecognized = implode("\n ", $unrecognized);
cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
}
+$diag = $options['diag'];
$drop = $options['drop'];
$install = $options['install'];
$buildconfig = $options['buildconfig'];
-if ($options['help'] or (!$drop and !$install and !$buildconfig)) {
+if ($options['help'] or (!$drop and !$install and !$buildconfig and !$diag)) {
$help = "Various PHPUnit utility functions
Options:
--drop Drop database and dataroot
--install Install database
--buildconfig Build /phpunit.xml from /phpunit.xml.dist that includes suites for all plugins and core
+--diag Diagnose installation and return error code only
+--run Execute PHPUnit tests (alternative for standard phpunit binary)
-h, --help Print out this help
Example:
-\$/usr/bin/php lib/phpunit/tool.php
+\$/usr/bin/php lib/phpunit/tool.php --install
";
echo $help;
- die;
+ exit(0);
}
-if ($buildconfig) {
- phpunit_util::build_config_file();
+if ($diag) {
+ list($errorcode, $message) = phpunit_util::testing_ready_problem();
+ if ($errorcode) {
+ phpunit_bootstrap_error($errorcode, $message);
+ }
exit(0);
+} else if ($buildconfig) {
+ if (phpunit_util::build_config_file()) {
+ exit(0);
+ } else {
+ phpunit_bootstrap_error(134);
+ }
+
} else if ($drop) {
+ // make sure tests do not run in parallel
+ phpunit_util::acquire_test_lock();
phpunit_util::drop_site();
// note: we must stop here because $CFG is messed up and we can not reinstall, sorry
exit(0);
View
4 admin/tool/phpunit/index.php
@@ -22,8 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-define('NO_OUTPUT_BUFFERING', true);
-
require(dirname(__FILE__) . '/../../../config.php');
require_once($CFG->libdir.'/adminlib.php');
@@ -37,4 +35,4 @@
echo markdown_to_html($info);
echo $OUTPUT->box_end();
-echo $OUTPUT->footer();
+echo $OUTPUT->footer();
View
6 admin/tool/phpunit/settings.php
@@ -25,4 +25,8 @@
defined('MOODLE_INTERNAL') || die;
-$ADMIN->add('development', new admin_externalpage('toolphpunit', get_string('pluginname', 'tool_phpunit'), "$CFG->wwwroot/$CFG->admin/tool/phpunit/index.php"));
+if ($hassiteconfig) {
+ $ADMIN->add('development', new admin_externalpage('toolphpunit', get_string('pluginname', 'tool_phpunit'), "$CFG->wwwroot/$CFG->admin/tool/phpunit/index.php"));
+ $ADMIN->add('development', new admin_externalpage('toolphpunitwebrunner', get_string('pluginname', 'tool_phpunit'), "$CFG->wwwroot/$CFG->admin/tool/phpunit/webrunner.php",
+ 'moodle/site:config', true));
+}
View
4 admin/tool/phpunit/version.php
@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2012030800; // The current plugin version (Date: YYYYMMDDXX)
-$plugin->requires = 2012030100; // Requires this Moodle version
+$plugin->version = 2012040500; // The current plugin version (Date: YYYYMMDDXX)
+$plugin->requires = 2012040500; // Requires this Moodle version
$plugin->component = 'tool_phpunit'; // Full name of the plugin (used for diagnostics)
View
192 admin/tool/phpunit/webrunner.php
@@ -0,0 +1,192 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * PHPUnit shell execution wrapper
+ *
+ * @package tool_phpunit
+ * @copyright 2012 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+define('NO_OUTPUT_BUFFERING', true);
+
+require(dirname(__FILE__) . '/../../../config.php');
+require_once($CFG->libdir.'/adminlib.php');
+
+$testpath = optional_param('testpath', '', PARAM_PATH);
+$testclass = optional_param('testclass', '', PARAM_ALPHANUMEXT);
+$execute = optional_param('execute', 0, PARAM_BOOL);
+
+navigation_node::override_active_url(new moodle_url('/admin/tool/phpunit/index.php'));
+admin_externalpage_setup('toolphpunitwebrunner');
+
+if (!debugging('', DEBUG_DEVELOPER)) {
+ error('Not available on production sites, sorry.');
+}
+
+set_time_limit(60*30);
+
+$oldcwd = getcwd();
+$code = 0;
+
+if (!isset($CFG->phpunit_dataroot) or !isset($CFG->phpunit_prefix)) {
+ tool_phpunit_problem('Missing $CFG->phpunit_dataroot or $CFG->phpunit_prefix, can not execute tests.');
+}
+if (!file_exists($CFG->phpunit_dataroot)) {
+ mkdir($CFG->phpunit_dataroot, 02777, true);
+}
+if (!is_writable($CFG->phpunit_dataroot)) {
+ tool_phpunit_problem('$CFG->phpunit_dataroot in not writable, can not execute tests.');
+}
+$output = null;
+exec('php --version', $output, $code);
+if ($code != 0) {
+ tool_phpunit_problem('Can not execute \'php\' binary.');
+}
+
+if ($execute) {
+ require_sesskey();
+
+ chdir($CFG->dirroot);
+ $output = null;
+ exec("php $CFG->admin/tool/phpunit/cli/util.php --diag", $output, $code);
+ if ($code == 0) {
+ // everything is ready
+
+ } else if ($code == 132) {
+ tool_phpunit_header();
+ echo $OUTPUT->box_start('generalbox');
+ echo '<pre>';
+ echo "Initialising test database:\n\n";
+ chdir($CFG->dirroot);
+ ignore_user_abort(true);
+ passthru("php $CFG->admin/tool/phpunit/cli/util.php --buildconfig", $code);
+ passthru("php $CFG->admin/tool/phpunit/cli/util.php --install", $code);
+ chdir($oldcwd);
+ echo '</pre>';
+ echo $OUTPUT->box_end();
+ if ($code != 0) {
+ tool_phpunit_problem('Can not initialize database');
+ }
+ $CFG->debug = 0; // no pesky redirect warning, we really want to redirect
+ redirect(new moodle_url($PAGE->url, array('execute'=>1, 'tespath'=>$testpath, 'testclass'=>$testclass, 'sesskey'=>sesskey())), 'Reloading page');
+ echo $OUTPUT->footer();
+ die();
+
+ } else if ($code == 133) {
+ tool_phpunit_header();
+ echo $OUTPUT->box_start('generalbox');
+ echo '<pre>';
+ echo "Reinitialising test database:\n\n";
+ chdir($CFG->dirroot);
+ ignore_user_abort(true);
+ passthru("php $CFG->admin/tool/phpunit/cli/util.php --drop", $code);
+ passthru("php $CFG->admin/tool/phpunit/cli/util.php --buildconfig", $code);
+ passthru("php $CFG->admin/tool/phpunit/cli/util.php --install", $code);
+ chdir($oldcwd);
+ echo '</pre>';
+ echo $OUTPUT->box_end();
+ if ($code != 0) {
+ tool_phpunit_problem('Can not initialize database');
+ }
+ $CFG->debug = 0; // no pesky redirect warning, we really want to redirect
+ redirect(new moodle_url($PAGE->url, array('execute'=>1, 'tespath'=>$testpath, 'testclass'=>$testclass, 'sesskey'=>sesskey())), 'Reloading page');
+ die();
+
+ } else {
+ tool_phpunit_header();
+ echo $OUTPUT->box_start('generalbox');
+ echo '<pre>';
+ echo "Error: $code\n\n";
+ echo implode("\n", $output);
+ echo '</pre>';
+ echo $OUTPUT->box_end();
+ tool_phpunit_problem('Can not execute tests');
+ die();
+ }
+
+ tool_phpunit_header();
+ echo $OUTPUT->box_start('generalbox');
+ echo '<pre>';
+
+ // use the dataroot file
+ $configdir = "$CFG->phpunit_dataroot/phpunit/webrunner.xml";
+ if (!file_exists($configdir)) {
+ passthru("php $CFG->admin/tool/phpunit/cli/util.php --buildconfig", $code);
+ if ($code != 0) {
+ tool_phpunit_problem('Can not create configuration file');
+ }
+ }
+ $configdir = escapeshellarg($configdir);
+ // no cleanup of path - this is tricky because we can not use escapeshellarg and friends for escaping,
+ // this is from admin user so PARAM_PATH must be enough
+ chdir($CFG->dirroot);
+ passthru("php $CFG->admin/tool/phpunit/cli/util.php --run -c $configdir $testclass $testpath", $code);
+ chdir($oldcwd);
+
+ echo '</pre>';
+ echo $OUTPUT->box_end();
+
+} else {
+ tool_phpunit_header();
+}
+
+echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
+echo '<form method="get" action="webrunner.php">';
+echo '<fieldset class="invisiblefieldset">';
+echo '<label for="testpath">Test one file</label> ';
+echo '<input type="text" id="testpath" name="testpath" value="'.s($testpath).'" size="50" /> (all test cases from webrunner.xml if empty)';
+echo '</p>';
+echo '<label for="testclass">Class name</label> ';
+echo '<input type="text" id="testclass" name="testclass" value="'.s($testclass).'" size="50" /> (first class in file if empty)';
+echo '</p>';
+echo '<input type="submit" value="Run" />';
+echo '<input type="hidden" name="execute" value="1" />';
+echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
+echo '</fieldset>';
+echo '</form>';
+echo $OUTPUT->box_end();
+echo $OUTPUT->footer();
+die;
+
+
+
+//========================================
+
+/**
+ * Print headers and experimental warning
+ * @return void
+ */
+function tool_phpunit_header() {
+ global $OUTPUT;
+ echo $OUTPUT->header();
+ echo $OUTPUT->heading(get_string('pluginname', 'tool_phpunit'));
+ echo $OUTPUT->box('EXPERIMENTAL: it is recommended to execute PHPUnit tests and init scripts only from command line.', array('generalbox'));
+}
+
+/**
+ * Called when PHPUnit can not execute.
+ * @param string $message
+ * @return void
+ */
+function tool_phpunit_problem($message) {
+ global $PAGE;
+ if (!$PAGE->headerprinted) {
+ tool_phpunit_header();
+ }
+ notice($message, new moodle_url('/admin/tool/phpunit/'));
+}
View
5 backup/moodle2/backup_activity_task.class.php
@@ -167,6 +167,11 @@ public function build() {
$this->add_step(new backup_activity_logs_structure_step('activity_logs', 'logs.xml'));
}
+ // Generate the calendar events file (conditionally)
+ if ($this->get_setting_value('calendarevents')) {
+ $this->add_step(new backup_calendarevents_structure_step('activity_calendar', 'calendar.xml'));
+ }
+
// Fetch all the activity grade items and put them to backup_ids
$this->add_step(new backup_activity_grade_items_to_ids('fetch_activity_grade_items'));
View
5 backup/moodle2/backup_course_task.class.php
@@ -106,6 +106,11 @@ public function build() {
$this->add_step(new backup_comments_structure_step('course_comments', 'comments.xml'));
}
+ // Generate the calender events file (conditionally)
+ if ($this->get_setting_value('calendarevents')) {
+ $this->add_step(new backup_calendarevents_structure_step('course_calendar', 'calendar.xml'));
+ }
+
// Generate the logs file (conditionally)
if ($this->get_setting_value('logs')) {
$this->add_step(new backup_course_logs_structure_step('course_logs', 'logs.xml'));
View
6 backup/moodle2/backup_root_task.class.php
@@ -119,6 +119,12 @@ protected function define_settings() {
$this->add_setting($comments);
$users->add_dependency($comments);
+ // Define calendar events (dependent of users)
+ $events = new backup_calendarevents_setting('calendarevents', base_setting::IS_BOOLEAN, true);
+ $events->set_ui(new backup_setting_ui_checkbox($events, get_string('rootsettingcalendarevents', 'backup')));
+ $this->add_setting($events);
+ $users->add_dependency($events);
+
// Define completion (dependent of users)
$completion = new backup_userscompletion_setting('userscompletion', base_setting::IS_BOOLEAN, true);
$completion->set_ui(new backup_setting_ui_checkbox($completion, get_string('rootsettinguserscompletion', 'backup')));
View
7 backup/moodle2/backup_settingslib.php
@@ -103,6 +103,13 @@ class backup_comments_setting extends backup_anonymize_setting {}
/**
* root setting to control if backup will include
+ * calender events or no (any level), depends of @backup_users_setting
+ * exactly in the same way than @backup_anonymize_setting so we extend from it
+ */
+class backup_calendarevents_setting extends backup_anonymize_setting {}
+
+/**
+ * root setting to control if backup will include
* users completion data or no (any level), depends of @backup_users_setting
* exactly in the same way than @backup_anonymize_setting so we extend from it
*/
View
42 backup/moodle2/backup_stepslib.php
@@ -763,6 +763,48 @@ protected function define_structure() {
}
/**
+ * structure step in charge of constructing the calender.xml file for all the events found
+ * in a given context
+ */
+class backup_calendarevents_structure_step extends backup_structure_step {
+
+ protected function define_structure() {
+
+ // Define each element separated
+
+ $events = new backup_nested_element('events');
+
+ $event = new backup_nested_element('event', array('id'), array(
+ 'name', 'description', 'format', 'courseid', 'groupid', 'userid',
+ 'repeatid', 'modulename', 'instance', 'eventtype', 'timestart',
+ 'timeduration', 'visible', 'uuid', 'sequence', 'timemodified'));
+
+ // Build the tree
+ $events->add_child($event);
+
+ // Define sources
+ if ($this->name == 'course_calendar') {
+ $calendar_items_sql ="SELECT * FROM {event}
+ WHERE courseid = :courseid
+ AND (eventtype = 'course' OR eventtype = 'group')";
+ $calendar_items_params = array('courseid'=>backup::VAR_COURSEID);
+ $event->set_source_sql($calendar_items_sql, $calendar_items_params);
+ } else {
+ $event->set_source_table('event', array('courseid' => backup::VAR_COURSEID, 'instance' => backup::VAR_ACTIVITYID, 'modulename' => backup::VAR_MODNAME));
+ }
+
+ // Define id annotations
+
+ $event->annotate_ids('user', 'userid');
+ $event->annotate_ids('group', 'groupid');
+ $event->annotate_files('calendar', 'event_description', 'id');
+
+ // Return the root element (events)
+ return $events;
+ }
+}
+
+/**
* structure step in charge of constructing the gradebook.xml file for all the gradebook config in the course
* NOTE: the backup of the grade items themselves is handled by backup_activity_grades_structure_step
*/
View
5 backup/moodle2/restore_activity_task.class.php
@@ -152,6 +152,11 @@ public function build() {
$this->add_step(new restore_comments_structure_step('activity_comments', 'comments.xml'));
}
+ // Calendar events (conditionally)
+ if ($this->get_setting_value('calendarevents')) {
+ $this->add_step(new restore_calendarevents_structure_step('activity_calendar', 'calendar.xml'));
+ }
+
// Grades (module-related, rest of gradebook is restored later if possible: cats, calculations...)
$this->add_step(new restore_activity_grades_structure_step('activity_grades', 'grades.xml'));
View
5 backup/moodle2/restore_course_task.class.php
@@ -89,6 +89,11 @@ public function build() {
$this->add_step(new restore_comments_structure_step('course_comments', 'comments.xml'));
}
+ // Calendar events (conditionally)
+ if ($this->get_setting_value('calendarevents')) {
+ $this->add_step(new restore_calendarevents_structure_step('course_calendar', 'calendar.xml'));
+ }
+
// At the end, mark it as built
$this->built = true;
}
View
13 backup/moodle2/restore_root_task.class.php
@@ -174,6 +174,19 @@ protected function define_settings() {
$this->add_setting($comments);
$users->add_dependency($comments);
+ // Define Calendar events (dependent of users)
+ $defaultvalue = false; // Safer default
+ $changeable = false;
+ if (isset($rootsettings['calendarevents']) && $rootsettings['calendarevents']) { // Only enabled when available
+ $defaultvalue = true;
+ $changeable = true;
+ }
+ $events = new restore_calendarevents_setting('calendarevents', base_setting::IS_BOOLEAN, $defaultvalue);
+ $events->set_ui(new backup_setting_ui_checkbox($events, get_string('rootsettingcalendarevents', 'backup')));
+ $events->get_ui()->set_changeable($changeable);
+ $this->add_setting($events);
+ $users->add_dependency($events);
+
// Define completion (dependent of users)
$defaultvalue = false; // Safer default
$changeable = false;
View
7 backup/moodle2/restore_settingslib.php
@@ -65,6 +65,13 @@ class restore_comments_setting extends restore_role_assignments_setting {}
/**
* root setting to control if restore will create
+ * events or no, depends of @restore_users_setting
+ * exactly in the same way than @restore_role_assignments_setting so we extend from it
+ */
+class restore_calendarevents_setting extends restore_role_assignments_setting {}
+
+/**
+ * root setting to control if restore will create
* completion info or no, depends of @restore_users_setting
* exactly in the same way than @restore_role_assignments_setting so we extend from it
*/
View
70 backup/moodle2/restore_stepslib.php
@@ -1596,6 +1596,76 @@ public function process_comment($data) {
}
}
+/**
+ * This structure steps restores the calendar events
+ */
+class restore_calendarevents_structure_step extends restore_structure_step {
+
+ protected function define_structure() {
+
+ $paths = array();
+
+ $paths[] = new restore_path_element('calendarevents', '/events/event');
+
+ return $paths;
+ }
+
+ public function process_calendarevents($data) {
+ global $DB;
+
+ $data = (object)$data;
+ $oldid = $data->id;
+ $restorefiles = true; // We'll restore the files
+ // Find the userid and the groupid associated with the event. Return if not found.
+ $data->userid = $this->get_mappingid('user', $data->userid);
+ if ($data->userid === false) {
+ return;
+ }
+ if (!empty($data->groupid)) {
+ $data->groupid = $this->get_mappingid('group', $data->groupid);
+ if ($data->groupid === false) {
+ return;
+ }
+ }
+
+ $params = array(
+ 'name' => $data->name,
+ 'description' => $data->description,
+ 'format' => $data->format,
+ 'courseid' => $this->get_courseid(),
+ 'groupid' => $data->groupid,
+ 'userid' => $data->userid,
+ 'repeatid' => $data->repeatid,
+ 'modulename' => $data->modulename,
+ 'eventtype' => $data->eventtype,
+ 'timestart' => $this->apply_date_offset($data->timestart),
+ 'timeduration' => $data->timeduration,
+ 'visible' => $data->visible,
+ 'uuid' => $data->uuid,
+ 'sequence' => $data->sequence,
+ 'timemodified' => $this->apply_date_offset($data->timemodified));
+ if ($this->name == 'activity_calendar') {
+ $params['instance'] = $this->task->get_activityid();
+ } else {
+ $params['instance'] = 0;
+ }
+ $sql = 'SELECT id FROM {event} WHERE name = ? AND courseid = ? AND
+ repeatid = ? AND modulename = ? AND timestart = ? AND timeduration =?
+ AND ' . $DB->sql_compare_text('description', 255) . ' = ' . $DB->sql_compare_text('?', 255);
+ $arg = array ($params['name'], $params['courseid'], $params['repeatid'], $params['modulename'], $params['timestart'], $params['timeduration'], $params['description']);
+ $result = $DB->record_exists_sql($sql, $arg);
+ if (empty($result)) {
+ $newitemid = $DB->insert_record('event', $params);
+ $this->set_mapping('event_description', $oldid, $newitemid, $restorefiles);
+ }
+
+ }
+ protected function after_execute() {
+ // Add related files
+ $this->add_related_files('calendar', 'event_description', 'event_description');
+ }
+}
+
class restore_course_completion_structure_step extends restore_structure_step {
/**
View
2  backup/util/factories/tests/factories_test.php
@@ -111,7 +111,7 @@ function test_backup_factory() {
$this->assertTrue($logger2 instanceof file_logger); // 2nd logger is file_logger (output_indented_logger skiped)
// Define extra file logger and instantiate, should be 5th and last logger
- $CFG->backup_file_logger_extra = '/tmp/test.html';
+ $CFG->backup_file_logger_extra = $CFG->tempdir.'/test.html';
$CFG->backup_file_logger_level_extra = backup::LOG_NONE;
$logger1 = backup_factory::get_logger_chain(backup::INTERACTIVE_YES, backup::EXECUTION_INMEDIATE, 'test');
$logger2 = $logger1->get_next();
View
2  backup/util/loggers/simpletest/testlogger.php
@@ -272,6 +272,7 @@ function test_file_logger() {
unlink($file); // delete file
// Try one html file
+ check_dir_exists($CFG->tempdir . '/test');
$file = $CFG->tempdir . '/test/test_file_logger.html';
$options = array('depth' => 1);
$lo = new file_logger(backup::LOG_ERROR, true, true, $file);
@@ -289,6 +290,7 @@ function test_file_logger() {
unlink($file); // delete file
// Instantiate, write something, force deletion, try to write again
+ check_dir_exists($CFG->tempdir . '/test');
$file = $CFG->tempdir . '/test/test_file_logger.html';
$lo = new mock_file_logger(backup::LOG_ERROR, true, true, $file);
$this->assertTrue(file_exists($file));
View
3  backup/util/loggers/tests/logger_test.php
@@ -267,6 +267,7 @@ function test_file_logger() {
unlink($file); // delete file
// Try one html file
+ check_dir_exists($CFG->tempdir . '/test');
$file = $CFG->tempdir . '/test/test_file_logger.html';
$options = array('depth' => 1);
$lo = new file_logger(backup::LOG_ERROR, true, true, $file);
@@ -281,9 +282,11 @@ function test_file_logger() {
$this->assertTrue(strpos($fcontents, '[error]') !== false);
$this->assertTrue(strpos($fcontents, '&nbsp;&nbsp;') !== false);
$this->assertTrue(substr_count($fcontents , '] ') >= 2);
+ $lo->__destruct(); // closes file handle
unlink($file); // delete file
// Instantiate, write something, force deletion, try to write again
+ check_dir_exists($CFG->tempdir . '/test');
$file = $CFG->tempdir . '/test/test_file_logger.html';
$lo = new mock_file_logger(backup::LOG_ERROR, true, true, $file);
$this->assertTrue(file_exists($file));
View
63 blocks/online_users/tests/generator/lib.php
@@ -0,0 +1,63 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * block_online_users data generator
+ *
+ * @package block_online_users
+ * @category phpunit
+ * @copyright 2012 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+
+/**
+ * Page module PHPUnit data generator class
+ *
+ * @package mod_page
+ * @category phpunit
+ * @copyright 2012 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class block_online_users_generator extends phpunit_block_generator {
+
+ /**
+ * Create new block instance
+ * @param array|stdClass $record
+ * @param array $options
+ * @return stdClass activity record with extra cmid field
+ */
+ public function create_instance($record = null, array $options = null) {
+ global $DB, $CFG;
+ require_once("$CFG->dirroot/mod/page/locallib.php");
+
+ $this->instancecount++;
+
+ $record = (object)(array)$record;
+ $options = (array)$options;
+
+ $record = $this->prepare_record($record);
+
+ $id = $DB->insert_record('block_instances', $record);
+ context_block::instance($id);
+
+ $instance = $DB->get_record('block_instances', array('id'=>$id), '*', MUST_EXIST);
+
+ return $instance;
+ }
+}
View
57 blocks/online_users/tests/generator_test.php
@@ -0,0 +1,57 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * PHPUnit data generator tests
+ *
+ * @package block_online_users
+ * @category phpunit
+ * @copyright 2012 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+
+/**
+ * PHPUnit data generator testcase
+ *
+ * @package block_online_users
+ * @category phpunit
+ * @copyright 2012 Petr Skoda {@link http://skodak.org}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class block_online_users_generator_testcase extends advanced_testcase {
+ public function test_generator() {
+ global $DB;
+
+ $this->resetAfterTest(true);
+
+ $beforeblocks = $DB->count_records('block_instances');
+ $beforecontexts = $DB->count_records('context');
+
+ /** @var block_online_users_generator $generator */
+ $generator = $this->getDataGenerator()->get_plugin_generator('block_online_users');
+ $this->assertInstanceOf('block_online_users_generator', $generator);
+ $this->assertEquals('online_users', $generator->get_blockname());
+
+ $generator->create_instance();
+ $generator->create_instance();
+ $bi = $generator->create_instance();
+ $this->assertEquals($beforeblocks+3, $DB->count_records('block_instances'));
+
+ }
+}
View
13 blog/locallib.php
@@ -292,9 +292,16 @@ public function print_html($return=false) {
$contentcell->text .= $OUTPUT->container_start('commands');
- if (blog_user_can_edit_entry($this) && empty($this->uniquehash)) {
- $contentcell->text .= html_writer::link(new moodle_url('/blog/edit.php', array('action' => 'edit', 'entryid' => $this->id)), $stredit) . ' | ';
- $contentcell->text .= html_writer::link(new moodle_url('/blog/edit.php', array('action' => 'delete', 'entryid' => $this->id)), $strdelete) . ' | ';
+ if (blog_user_can_edit_entry($this)) {
+ if (empty($this->uniquehash)) {
+ //External blog entries should not be edited
+ $contentcell->text .= html_writer::link(new moodle_url('/blog/edit.php',
+ array('action' => 'edit', 'entryid' => $this->id)),
+ $stredit) . ' | ';
+ }
+ $contentcell->text .= html_writer::link(new moodle_url('/blog/edit.php',
+ array('action' => 'delete', 'entryid' => $this->id)),
+ $strdelete) . ' | ';
}
$contentcell->text .= html_writer::link(new moodle_url('/blog/index.php', array('entryid' => $this->id)), get_string('permalink', 'blog'));
View
25 blog/tests/bloglib_test.php
@@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-
/**
* Unit tests for blog
*
@@ -35,19 +34,23 @@
class bloglib_testcase extends advanced_testcase {
private $courseid; // To store important ids to be used in tests
+ private $cmid;
private $groupid;
private $userid;
private $tagid;
+ private $postid;
protected function setUp() {
global $DB;
parent::setUp();
- $this->resetAfterTest(true);
+ $this->resetAfterTest();
// Create default course
- $course = $this->getDataGenerator()->create_course(array('category'=>1, 'fullname'=>'Anonymous test course', 'shortname'=>'ANON'));
+ $course = $this->getDataGenerator()->create_course(array('category'=>1, 'shortname'=>'ANON'));
+ $this->assertNotEmpty($course);
$page = $this->getDataGenerator()->create_module('page', array('course'=>$course->id));
+ $this->assertNotEmpty($page);
// Create default group
$group = new stdClass();
@@ -75,17 +78,20 @@ protected function setUp() {
// Grab important ids
$this->courseid = $course->id;
+ $this->cmid = $page->cmid;
$this->groupid = $group->id;
$this->userid = $user->id;
$this->tagid = $tag->id;
+ $this->postid = $post->id;
}
public function test_overrides() {
+ global $SITE;
// Try all the filters at once: Only the entry filter is active
- $filters = array('site' => 1, 'course' => $this->courseid, 'module' => 1,
- 'group' => $this->groupid, 'user' => 1, 'tag' => 1, 'entry' => 1);
+ $filters = array('site' => $SITE->id, 'course' => $this->courseid, 'module' => $this->cmid,
+ 'group' => $this->groupid, 'user' => $this->userid, 'tag' => $this->tagid, 'entry' => $this->postid);
$blog_listing = new blog_listing($filters);
$this->assertFalse(array_key_exists('site', $blog_listing->filters));
$this->assertFalse(array_key_exists('course', $blog_listing->filters));
@@ -96,8 +102,8 @@ public function test_overrides() {
$this->assertTrue(array_key_exists('entry', $blog_listing->filters));
// Again, but without the entry filter: This time, the tag, user and module filters are active
- $filters = array('site' => 1, 'course' => $this->courseid, 'module' => 1,
- 'group' => $this->groupid, 'user' => 1, 'tag' => 1);
+ $filters = array('site' => $SITE->id, 'course' => $this->courseid, 'module' => $this->cmid,
+ 'group' => $this->groupid, 'user' => $this->userid, 'tag' => $this->postid);
$blog_listing = new blog_listing($filters);
$this->assertFalse(array_key_exists('site', $blog_listing->filters));
$this->assertFalse(array_key_exists('course', $blog_listing->filters));
@@ -107,7 +113,7 @@ public function test_overrides() {
$this->assertTrue(array_key_exists('tag', $blog_listing->filters));
// We should get the same result by removing the 3 inactive filters: site, course and group:
- $filters = array('module' => 1, 'user' => 1, 'tag' => 1);
+ $filters = array('module' => $this->cmid, 'user' => $this->userid, 'tag' => $this->tagid);
$blog_listing = new blog_listing($filters);
$this->assertFalse(array_key_exists('site', $blog_listing->filters));
$this->assertFalse(array_key_exists('course', $blog_listing->filters));
@@ -135,9 +141,10 @@ public function test_blog_get_headers_case_6() {
public function test_blog_get_headers_case_7() {
global $CFG, $PAGE, $OUTPUT;
- $blog_headers = blog_get_headers(NULL, 1);
+ $blog_headers = blog_get_headers(NULL, $this->groupid);
$this->assertNotEquals($blog_headers['heading'], '');
}
+
public function test_blog_get_headers_case_10() {
global $CFG, $PAGE, $OUTPUT;
$blog_headers = blog_get_headers($this->courseid);
View
6 config-dist.php
@@ -490,12 +490,6 @@
// $CFG->phpunit_prefix = 'phpu_';
// $CFG->phpunit_dataroot = '/home/example/phpu_moodledata';
// $CFG->phpunit_directorypermissions = 02777; // optional
-// $CFG->phpunit_extra_drivers = array(
-// 1=>array('dbtype'=>'mysqli', 'dbhost'=>'localhost', 'dbname'=>'moodle', 'dbuser'=>'root', 'dbpass'=>'', 'prefix'=>'phpu2_'),
-// 2=>array('dbtype'=>'pgsql', 'dbhost'=>'localhost', 'dbname'=>'moodle', 'dbuser'=>'postgres', 'dbpass'=>'', 'prefix'=>'phpu2_'),
-// 3=>array('dbtype'=>'sqlsrv', 'dbhost'=>'127.0.0.1', 'dbname'=>'moodle', 'dbuser'=>'sa', 'dbpass'=>'', 'prefix'=>'phpu2_'),
-// 4=>array('dbtype'=>'oci', 'dbhost'=>'127.0.0.1', 'dbname'=>'XE', 'dbuser'=>'sa', 'dbpass'=>'', 'prefix'=>'t_'),
-// ); // for database driver testing only, DB is selected via PHPUNIT_TEST_DRIVER=n
//=========================================================================
// ALL DONE! To continue installation, visit your main page with a browser
View
6 index.php
@@ -35,7 +35,7 @@
redirect_if_major_upgrade_required();
$urlparams = array();
- if ($CFG->defaulthomepage == HOMEPAGE_MY && optional_param('redirect', 1, PARAM_BOOL) === 0) {
+ if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && optional_param('redirect', 1, PARAM_BOOL) === 0) {
$urlparams['redirect'] = 0;
}
$PAGE->set_url('/', $urlparams);
@@ -62,9 +62,9 @@
// Redirect logged-in users to My Moodle overview if required
if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
set_user_preference('user_home_page_preference', HOMEPAGE_SITE);
- } else if ($CFG->defaulthomepage == HOMEPAGE_MY && optional_param('redirect', 1, PARAM_BOOL) === 1) {
+ } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && optional_param('redirect', 1, PARAM_BOOL) === 1) {
redirect($CFG->wwwroot .'/my/');
- } else if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_USER) {
+ } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_USER)) {
$PAGE->settingsnav->get('usercurrentsettings')->add(get_string('makethismyhome'), new moodle_url('/', array('setdefaulthome'=>true)), navigation_node::TYPE_SETTING);
}
}
View
12 install/lang/de/error.php
@@ -30,13 +30,13 @@
defined('MOODLE_INTERNAL') || die();
-$string['cannotcreatelangdir'] = 'Verzeichnis "lang" kann nicht angelegt werden';
-$string['cannotcreatetempdir'] = 'Das Verzeichnis "temp" kann nicht angelegt werden.';
-$string['cannotdownloadcomponents'] = 'Einige Komponenten können nicht heruntergeladen werden.';
+$string['cannotcreatelangdir'] = 'Verzeichnis \'lang\' wurde nicht angelegt';
+$string['cannotcreatetempdir'] = 'Das Verzeichnis \'temp\' wurde nicht angelegt';
+$string['cannotdownloadcomponents'] = 'Einige Komponenten können nicht geladen werden.';
$string['cannotdownloadzipfile'] = 'ZIP-Datei kann nicht heruntergeladen werden.';
-$string['cannotfindcomponent'] = 'Eine Komponente kann nicht gefunden werden';
-$string['cannotsavemd5file'] = 'Die md5-Datei kann nicht gespeichert werden';
-$string['cannotsavezipfile'] = 'Die ZIP-Datei kann nicht gespeichert werden';
+$string['cannotfindcomponent'] = 'Komponente wurde nicht gefunden';
+$string['cannotsavemd5file'] = 'Die md5-Datei wurde nicht gespeichert';
+$string['cannotsavezipfile'] = 'Die ZIP-Datei wurde nicht gespeichert';
$string['cannotunzipfile'] = 'Die Datei kann nicht entpackt werden';
$string['componentisuptodate'] = 'Die Komponente ist aktuell.';
$string['downloadedfilecheckfailed'] = 'Die Überprüfung der heruntergeladenen Datei ist gescheitert';
View
35 install/lang/de_comm/langconfig.php
@@ -0,0 +1,35 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Automatically generated strings for Moodle 2.3dev installer
+ *
+ * Do not edit this file manually! It contains just a subset of strings
+ * needed during the very first steps of installation. This file was
+ * generated automatically by export-installer.php (which is part of AMOS
+ * {@link http://docs.moodle.org/dev/Languages/AMOS}) using the
+ * list of strings defined in /install/stringnames.txt.
+ *
+ * @package installer
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$string['parentlanguage'] = 'de';
+$string['thisdirection'] = 'ltr';
+$string['thislanguage'] = 'Deutsch community';
View
1  lang/en/backup.php
@@ -203,6 +203,7 @@
$string['rootsettingblocks'] = 'Include blocks';
$string['rootsettingfilters'] = 'Include filters';
$string['rootsettingcomments'] = 'Include comments';
+$string['rootsettingcalendarevents'] = 'Include calendar events';
$string['rootsettinguserscompletion'] = 'Include user completion details';
$string['rootsettinglogs'] = 'Include course logs';
$string['rootsettinggradehistories'] = 'Include grade history';
View
13 lang/en/question.php
@@ -323,14 +323,18 @@
$string['flagged'] = 'Flagged';
$string['flagthisquestion'] = 'Flag this question';
$string['generalfeedback'] = 'General feedback';
-$string['generalfeedback_help'] = 'General feedback is shown to the student after they have attempted the question. Unlike feedback, which depends on the question type and what response the student gave, the same general feedback text is shown to all students.
+$string['generalfeedback_help'] = 'General feedback is shown to the student after they have completed the question. Unlike specific feedback, which depends on the question type and what response the student gave, the same general feedback text is shown to all students.
-You can use the general feedback to give students some background to what knowledge the question was testing, or give them a link to more information they can use if they did not understand the questions.';
+You can use the general feedback to give students a fully worked answer and perhaps a link to more information they can use if they did not understand the questions.';
$string['hidden'] = 'Hidden';
$string['hintn'] = 'Hint {no}';
$string['hinttext'] = 'Hint text';
$string['howquestionsbehave'] = 'How questions behave';
-$string['howquestionsbehave_help'] = 'Students can interact with the questions in the quiz in various different ways. For example, you may wish the students to enter an answer to each question and then submit the entire quiz, before anything is graded or they get any feedback. That would be \'Deferred feedback\' mode. Alternatively, you may wish for students to submit each question as they go along to get immediate feedback, and if they do not get it right immediately, have another try for fewer marks. That would be \'Interactive with multiple tries\' mode.';
+$string['howquestionsbehave_help'] = 'Students can interact with the questions in the quiz in various different ways. For example, you may wish the students to enter an answer to each question and then submit the entire quiz, before anything is graded or they get any feedback. That would be \'Deferred feedback\' mode.
+
+Alternatively, you may wish for students to submit each question as they go along to get immediate feedback, and if they do not get it right immediately, have another try for fewer marks. That would be \'Interactive with multiple tries\' mode.
+
+Those are probably the two most commonly used modes of behaviour. ';
$string['importfromcoursefiles'] = '... or choose a course file to import.';
$string['importfromupload'] = 'Select a file to upload ...';
$string['includesubcategories'] = 'Also show questions from sub-categories';
@@ -377,6 +381,7 @@
$string['restart'] = 'Start again';
$string['restartwiththeseoptions'] = 'Start again with these options';
$string['rightanswer'] = 'Right answer';
+$string['rightanswer_help'] = 'an automatically generated summary of the correct response. This can be limited, so you may wish to consider explaining the correct solution in the general feedback for the question, and turning this option off.';
$string['saved'] = 'Saved: {$a}';
$string['saveflags'] = 'Save the state of the flags';
$string['settingsformultipletries'] = 'Settings for multiple tries';
@@ -388,6 +393,7 @@
$string['shownumpartscorrect'] = 'Show the number of correct responses';
$string['shownumpartscorrectwhenfinished'] = 'Show the number of correct responses once the question has finished';
$string['specificfeedback'] = 'Specific feedback';
+$string['specificfeedback_help'] = 'Feedback that depends on what response the student gave.';
$string['started'] = 'Started';
$string['state'] = 'State';
$string['step'] = 'Step';
@@ -401,6 +407,7 @@
$string['unknownquestioncatregory'] = 'Unknown question category: {$a}.';
$string['unknownquestiontype'] = 'Unknown question type: {$a}.';
$string['whethercorrect'] = 'Whether correct';
+$string['whethercorrect_help'] = 'This covers both the textual description \'Correct\', \'Partially correct\' or \'Incorrect\', and any coloured highlighting that conveys the same information.';
$string['withselected'] = 'With selected';
$string['xoutofmax'] = '{$a->mark} out of {$a->max}';
$string['yougotnright'] = 'You have correctly selected {$a->num}.';
View
2  lib/clilib.php
@@ -24,7 +24,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-defined('MOODLE_INTERNAL') || die();
+// NOTE: no MOODLE_INTERNAL test here, sometimes we use this before requiring Moodle libs!
/**
* Get input from user
View
7 lib/cronlib.php
@@ -650,7 +650,8 @@ function notify_login_failures() {
// Now, select all the login error logged records belonging to the ips and infos
// since lastnotifyfailure, that we have stored in the cache_flags table
- $sql = "SELECT l.*, u.firstname, u.lastname
+ $sql = "SELECT * FROM (
+ SELECT l.*, u.firstname, u.lastname
FROM {log} l
JOIN {cache_flags} cf ON l.ip = cf.name
LEFT JOIN {user} u ON l.userid = u.id
@@ -664,8 +665,8 @@ function notify_login_failures() {
LEFT JOIN {user} u ON l.userid = u.id
WHERE l.module = 'login' AND l.action = 'error'
AND l.time > ?
- AND cf.flagtype = 'login_failure_by_info'
- ORDER BY time DESC";
+ AND cf.flagtype = 'login_failure_by_info') t
+ ORDER BY t.time DESC";
$params = array($CFG->lastnotifyfailure, $CFG->lastnotifyfailure);
// Init some variables
View
14 lib/ddl/mssql_sql_generator.php
@@ -82,12 +82,22 @@ public function getResetSequenceSQL($table) {
$table = new xmldb_table($table);
}
- // From http://msdn.microsoft.com/en-us/library/ms176057.aspx
$value = (int)$this->mdb->get_field_sql('SELECT MAX(id) FROM {'. $table->getName() . '}');
+ $sqls = array();
+
+ // MSSQL has one non-consistent behavior to create the first identity value, depending
+ // if the table has been truncated or no. If you are really interested, you can find the
+ // whole description of the problem at:
+ // http://www.justinneff.com/archive/tag/dbcc-checkident
if ($value == 0) {
+ // truncate to get consistent result from reseed
+ $sqls[] = "TRUNCATE TABLE " . $this->getTableName($table);
$value = 1;
}
- return array("DBCC CHECKIDENT ('" . $this->getTableName($table) . "', RESEED, $value)");
+
+ // From http://msdn.microsoft.com/en-us/library/ms176057.aspx
+ $sqls[] = "DBCC CHECKIDENT ('" . $this->getTableName($table) . "', RESEED, $value)";
+ return $sqls;
}
/**
View
9 lib/ddl/simpletest/testddl.php
@@ -1626,7 +1626,14 @@ public function test_reset_sequence() {
$record = (object)array('id'=>666, 'course'=>10);
$DB->import_record('testtable', $record);
- $DB->delete_records('testtable');
+ $DB->delete_records('testtable'); // This delete performs one TRUNCATE
+
+ $dbman->reset_sequence($table); // using xmldb object
+ $this->assertEqual(1, $DB->insert_record('testtable', (object)array('course'=>13)));
+
+ $record = (object)array('id'=>666, 'course'=>10);
+ $DB->import_record('testtable', $record);
+ $DB->delete_records('testtable', array()); // This delete performs one DELETE
$dbman->reset_sequence($table); // using xmldb object
$this->assertEqual(1, $DB->insert_record('testtable', (object)array('course'=>13)));
View
15 lib/ddl/tests/ddl_test.php
@@ -31,10 +31,8 @@ class ddl_testcase extends database_driver_testcase {
private $records= array();
protected function setUp() {
- //global $CFG;
- //require_once($CFG->libdir . '/adminlib.php');
-
parent::setUp();
+ $dbman = $this->tdb->get_manager(); // loads DDL libs
$table = new xmldb_table('test_table0');
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
@@ -131,6 +129,8 @@ private function create_deftable($tablename) {
* Fill the given test table with some records, as far as
* DDL behaviour must be tested both with real data and
* with empty tables
+ * @param string $tablename
+ * @return int count of records
*/
private function fill_deftable($tablename) {
$DB = $this->tdb; // do not use global $DB!
@@ -1600,7 +1600,14 @@ public function test_reset_sequence() {
$record = (object)array('id'=>666, 'course'=>10);
$DB->import_record('testtable', $record);
- $DB->delete_records('testtable');
+ $DB->delete_records('testtable'); // This delete performs one TRUNCATE
+
+ $dbman->reset_sequence($table); // using xmldb object
+ $this->assertEquals(1, $DB->insert_record('testtable', (object)array('course'=>13)));
+
+ $record = (object)array('id'=>666, 'course'=>10);
+ $DB->import_record('testtable', $record);
+ $DB->delete_records('testtable', array()); // This delete performs one DELETE
$dbman->reset_sequence($table); // using xmldb object
$this->assertEquals(1, $DB->insert_record('testtable', (object)array('course'=>13)));
View
1  lib/dml/database_column_info.php
@@ -152,7 +152,6 @@ public function __construct($data) {
switch ($this->meta_type) {
case 'R': // normalise counters (usually 'id')
- $this->auto_increment = true;
$this->binary = false;
$this->has_default = false;
$this->default_value = null;
View
6 lib/dml/moodle_database.php
@@ -324,7 +324,11 @@ public function dispose() {
$lowesttransaction = end($this->transactions);
$backtrace = $lowesttransaction->get_backtrace();
- error_log('Potential coding error - active database transaction detected when disposing database:'."\n".format_backtrace($backtrace, true));
+ if (defined('PHPUNIT_TEST') and PHPUNIT_TEST) {
+ //no need to log sudden exits in our PHPunit test cases
+ } else {
+ error_log('Potential coding error - active database transaction detected when disposing database:'."\n".format_backtrace($backtrace, true));
+ }
$this->force_transaction_rollback();
}
if ($this->used_for_db_sessions) {
View
47 lib/dml/mssql_native_moodle_database.php
@@ -287,6 +287,13 @@ public function get_server_info() {
return $info;
}
+ /**
+ * Returns if the RDBMS server fulfills the required version
+ *
+ * @param string $version version to check against
+ * @return bool returns if the version is fulfilled (true) or no (false)
+ * @todo Delete this unused and protected method. MDL-32392
+ */
protected function is_min_version($version) {
$server = $this->get_server_info();
$server = $server['version'];
@@ -805,6 +812,7 @@ public function insert_record_raw($table, $params, $returnid=true, $bulk=false,
}
$returning = "";
+ $isidentity = false;
if ($customsequence) {
if (!isset($params['id'])) {
@@ -812,13 +820,21 @@ public function insert_record_raw($table, $params, $returnid=true, $bulk=false,
}
$returnid = false;
- // Disable IDENTITY column before inserting record with id
- $sql = 'SET IDENTITY_INSERT {' . $table . '} ON'; // Yes, it' ON!!
- list($sql, $xparams, $xtype) = $this->fix_sql_params($sql, null);
- $this->query_start($sql, null, SQL_QUERY_AUX);
- $result = mssql_query($sql, $this->mssql);
- $this->query_end($result);
- $this->free_result($result);
+ $columns = $this->get_columns($table);
+ if (isset($columns['id']) and $columns['id']->auto_increment) {
+ $isidentity = true;
+ }
+
+ // Disable IDENTITY column before inserting record with id, only if the
+ // column is identity, from meta information.
+ if ($isidentity) {
+ $sql = 'SET IDENTITY_INSERT {' . $table . '} ON'; // Yes, it' ON!!
+ list($sql, $xparams, $xtype) = $this->fix_sql_params($sql, null);
+ $this->query_start($sql, null, SQL_QUERY_AUX);
+ $result = mssql_query($sql, $this->mssql);
+ $this->query_end($result);
+ $this->free_result($result);
+ }
} else {
unset($params['id']);
@@ -851,13 +867,16 @@ public function insert_record_raw($table, $params, $returnid=true, $bulk=false,
$this->free_result($result);
if ($customsequence) {
- // Enable IDENTITY column after inserting record with id
- $sql = 'SET IDENTITY_INSERT {' . $table . '} OFF'; // Yes, it' OFF!!
- list($sql, $xparams, $xtype) = $this->fix_sql_params($sql, null);
- $this->query_start($sql, null, SQL_QUERY_AUX);
- $result = mssql_query($sql, $this->mssql);
- $this->query_end($result);
- $this->free_result($result);
+ // Enable IDENTITY column after inserting record with id, only if the
+ // column is identity, from meta information.
+ if ($isidentity) {
+ $sql = 'SET IDENTITY_INSERT {' . $table . '} OFF'; // Yes, it' OFF!!
+ list($sql, $xparams, $xtype) = $this->fix_sql_params($sql, null);
+ $this->query_start($sql, null, SQL_QUERY_AUX);
+ $result = mssql_query($sql, $this->mssql);
+ $this->query_end($result);
+ $this->free_result($result);
+ }
}
if (!$returnid) {
View
3  lib/dml/mysqli_native_moodle_database.php
@@ -485,7 +485,6 @@ public function get_columns($table, $usecache=true) {
$rawcolumn->is_nullable = $rawcolumn->null; unset($rawcolumn->null);
$rawcolumn->column_default = $rawcolumn->default; unset($rawcolumn->default);
$rawcolumn->column_key = $rawcolumn->key; unset($rawcolumn->default);
- $rawcolumn->extra = ($rawcolumn->column_name === 'id') ? 'auto_increment' : '';
if (preg_match('/(enum|varchar)\((\d+)\)/i', $rawcolumn->column_type, $matches)) {
$rawcolumn->data_type = $matches[1];
@@ -955,7 +954,7 @@ public function insert_record_raw($table, $params, $returnid=true, $bulk=false,
$id = @$this->mysqli->insert_id; // must be called before query_end() which may insert log into db
$this->query_end($result);
- if (!$id) {
+ if (!$customsequence and !$id) {
throw new dml_write_exception('unknown error fetching inserted id');
}
View
21 lib/dml/oci_native_moodle_database.php
@@ -296,6 +296,13 @@ public function get_server_info() {
return $info;
}
+ /**
+ * Returns if the RDBMS server fulfills the required version
+ *
+ * @param string $version version to check against
+ * @return bool returns if the version is fulfilled (true) or no (false)
+ * @todo Delete this unused and protected method. MDL-32392
+ */
protected function is_min_version($version) {
$server = $this->get_server_info();
$server = $server['version'];
@@ -493,9 +500,13 @@ public function get_columns($table, $usecache=true) {
// We give precedence to CHAR_LENGTH for VARCHAR2 columns over WIDTH because the former is always
// BYTE based and, for cross-db operations, we want CHAR based results. See MDL-29415
- $sql = "SELECT CNAME, COLTYPE, nvl(CHAR_LENGTH, WIDTH) AS WIDTH, SCALE, PRECISION, NULLS, DEFAULTVAL
+ // Instead of guessing sequence based exclusively on name, check tables against user_triggers to
+ // ensure the table has a 'before each row' trigger to assume 'id' is auto_increment. MDL-32365
+ $sql = "SELECT CNAME, COLTYPE, nvl(CHAR_LENGTH, WIDTH) AS WIDTH, SCALE, PRECISION, NULLS, DEFAULTVAL,
+ DECODE(NVL(TRIGGER_NAME, '0'), '0', '0', '1') HASTRIGGER
FROM COL c
LEFT JOIN USER_TAB_COLUMNS u ON (u.TABLE_NAME = c.TNAME AND u.COLUMN_NAME = c.CNAME AND u.DATA_TYPE = 'VARCHAR2')
+ LEFT JOIN USER_TRIGGERS t ON (t.TABLE_NAME = c.TNAME AND TRIGGER_TYPE = 'BEFORE EACH ROW' AND c.CNAME = 'ID')
WHERE TNAME = UPPER('{" . $table . "}')
ORDER BY COLNO";
@@ -517,6 +528,7 @@ public function get_columns($table, $usecache=true) {
$info = new stdClass();
$info->name = strtolower($rawcolumn->CNAME);
+ $info->auto_increment = ((int)$rawcolumn->HASTRIGGER) ? true : false;
$matches = null;
if ($rawcolumn->COLTYPE === 'VARCHAR2'
@@ -550,7 +562,6 @@ public function get_columns($table, $usecache=true) {
$info->primary_key = false;
$info->binary = false;
$info->unsigned = null;
- $info->auto_increment= false;
$info->unique = null;
} else if ($rawcolumn->COLTYPE === 'NUMBER') {
@@ -563,13 +574,11 @@ public function get_columns($table, $usecache=true) {
$info->primary_key = true;
$info->meta_type = 'R';
$info->unique = true;
- $info->auto_increment= true;
$info->has_default = false;
} else {
$info->primary_key = false;
$info->meta_type = 'I';
$info->unique = null;
- $info->auto_increment= false;
}
$info->scale = null;
@@ -578,7 +587,6 @@ public function get_columns($table, $usecache=true) {
$info->meta_type = 'N';
$info->primary_key = false;
$info->unsigned = null;
- $info->auto_increment= false;
$info->unique = null;
$info->scale = $rawcolumn->SCALE;
}
@@ -596,7 +604,6 @@ public function get_columns($table, $usecache=true) {
$info->primary_key = false;
$info->meta_type = 'N';
$info->unique = null;
- $info->auto_increment= false;
$info->not_null = ($rawcolumn->NULLS === 'NOT NULL');
$info->has_default = !is_null($rawcolumn->DEFAULTVAL);
if ($info->has_default) {
@@ -632,7 +639,6 @@ public function get_columns($table, $usecache=true) {
$info->primary_key = false;
$info->binary = false;
$info->unsigned = null;
- $info->auto_increment= false;
$info->unique = null;
} else if ($rawcolumn->COLTYPE === 'BLOB') {
@@ -661,7 +667,6 @@ public function get_columns($table, $usecache=true) {
$info->primary_key = false;
$info->binary = true;
$info->unsigned = null;
- $info->auto_increment= false;
$info->unique = null;
} else {
View
17 lib/dml/pgsql_native_moodle_database.php
@@ -179,8 +179,14 @@ public function connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, array $dbop
pg_set_client_encoding($this->pgsql, 'utf8');
$this->query_end(true);
- // find out the bytea oid
- $sql = "SELECT oid FROM pg_type WHERE typname = 'bytea'";
+ $sql = '';
+ // Only for 9.0 and upwards, set bytea encoding to old format.
+ if ($this->is_min_version('9.0')) {
+ $sql = "SET bytea_output = 'escape'; ";
+ }
+
+ // Find out the bytea oid.
+ $sql .= "SELECT oid FROM pg_type WHERE typname = 'bytea'";
$this->query_start($sql, null, SQL_QUERY_AUX);
$result = pg_query($this->pgsql, $sql);
$this->query_end($result);
@@ -251,6 +257,13 @@ public function get_server_info() {
return array('description'=>$info['server'], 'version'=>$info['server']);
}
+ /**
+ * Returns if the RDBMS server fulfills the required version
+ *
+ * @param string $version version to check against
+ * @return bool returns if the version is fulfilled (true) or no (false)
+ * @todo Make this method private. MDL-32392
+ */
protected function is_min_version($version) {
$server = $this->get_server_info();
$server = $server['version'];