Skip to content

Commit 7aa4e2a

Browse files
committed
merge from master
2 parents b3b4d7d + 5db19e1 commit 7aa4e2a

15 files changed

+439
-57
lines changed

.github/workflows/moodle-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,4 @@ jobs:
192192

193193
- name: Behat features
194194
if: ${{ always() }}
195-
run: moodle-plugin-ci behat --auto-rerun 0
195+
run: moodle-plugin-ci behat --auto-rerun 0

classes/capabilities.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class capabilities {
7474
/** capability review post to be published*/
7575
const REVIEW_POST = 'mod/moodleoverflow:reviewpost';
7676

77+
/** @var array cache capabilities*/
78+
private static $cache = [];
79+
7780
/**
7881
* Saves the cache from has_capability.
7982
*
@@ -91,11 +94,11 @@ public static function has(string $capability, context $context, $userid = null)
9194

9295
$key = "$userid:$context->id:$capability";
9396

94-
if (!isset($cache[$key])) {
95-
$cache[$key] = has_capability($capability, $context, $userid);
97+
if (!isset(self::$cache[$key])) {
98+
self::$cache[$key] = has_capability($capability, $context, $userid);
9699
}
97100

98-
return $cache[$key];
101+
return self::$cache[$key];
99102
}
100103

101104
}

classes/post_form.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public function definition() {
5858
$modform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
5959

6060
// The message.
61-
$modform->addElement('editor', 'message', get_string('message', 'moodleoverflow'), null);
61+
$modform->addElement('editor', 'message', get_string('message', 'moodleoverflow'), null,
62+
self::editor_options($modcontext, (empty($post->id) ? null : $post->id)));
6263
$modform->setType('message', PARAM_RAW);
6364
$modform->addRule('message', get_string('required'), 'required', null, 'client');
6465

@@ -141,6 +142,25 @@ public static function attachment_options($moodleoverflow) {
141142
'return_types' => FILE_INTERNAL | FILE_CONTROLLED_LINK,
142143
];
143144
}
145+
146+
/**
147+
* Returns the options array to use in forum text editor
148+
*
149+
* @param context_module $context
150+
* @param int $postid post id, use null when adding new post
151+
* @return array
152+
*/
153+
public static function editor_options(context_module $context, $postid) {
154+
global $COURSE, $PAGE, $CFG;
155+
$maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes);
156+
return [
157+
'maxfiles' => EDITOR_UNLIMITED_FILES,
158+
'maxbytes' => $maxbytes,
159+
'trusttext' => true,
160+
'return_types' => FILE_INTERNAL | FILE_EXTERNAL,
161+
'subdirs' => file_area_contains_subdirs($context, 'mod_forum', 'post', $postid),
162+
];
163+
}
144164
}
145165

146166

db/upgrade.php

+8
Original file line numberDiff line numberDiff line change
@@ -292,5 +292,13 @@ function xmldb_moodleoverflow_upgrade($oldversion) {
292292
upgrade_mod_savepoint(true, 2023040400, 'moodleoverflow');
293293
}
294294

295+
if ($oldversion < 2024072600) {
296+
require_once($CFG->dirroot . '/mod/moodleoverflow/db/upgradelib.php');
297+
298+
mod_moodleoverflow_move_draftfiles_to_permanent_filearea();
299+
300+
upgrade_mod_savepoint(true, 2024072600, 'moodleoverflow');
301+
}
302+
295303
return true;
296304
}

0 commit comments

Comments
 (0)