Skip to content

Commit

Permalink
merge from master
Browse files Browse the repository at this point in the history
  • Loading branch information
TamaroWalter committed Sep 9, 2024
2 parents b3b4d7d + 5db19e1 commit 7aa4e2a
Show file tree
Hide file tree
Showing 15 changed files with 439 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,4 @@ jobs:

- name: Behat features
if: ${{ always() }}
run: moodle-plugin-ci behat --auto-rerun 0
run: moodle-plugin-ci behat --auto-rerun 0
9 changes: 6 additions & 3 deletions classes/capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class capabilities {
/** capability review post to be published*/
const REVIEW_POST = 'mod/moodleoverflow:reviewpost';

/** @var array cache capabilities*/
private static $cache = [];

/**
* Saves the cache from has_capability.
*
Expand All @@ -91,11 +94,11 @@ public static function has(string $capability, context $context, $userid = null)

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

if (!isset($cache[$key])) {
$cache[$key] = has_capability($capability, $context, $userid);
if (!isset(self::$cache[$key])) {
self::$cache[$key] = has_capability($capability, $context, $userid);
}

return $cache[$key];
return self::$cache[$key];
}

}
22 changes: 21 additions & 1 deletion classes/post_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public function definition() {
$modform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');

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

Expand Down Expand Up @@ -141,6 +142,25 @@ public static function attachment_options($moodleoverflow) {
'return_types' => FILE_INTERNAL | FILE_CONTROLLED_LINK,
];
}

/**
* Returns the options array to use in forum text editor
*
* @param context_module $context
* @param int $postid post id, use null when adding new post
* @return array
*/
public static function editor_options(context_module $context, $postid) {
global $COURSE, $PAGE, $CFG;
$maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes);
return [
'maxfiles' => EDITOR_UNLIMITED_FILES,
'maxbytes' => $maxbytes,
'trusttext' => true,
'return_types' => FILE_INTERNAL | FILE_EXTERNAL,
'subdirs' => file_area_contains_subdirs($context, 'mod_forum', 'post', $postid),
];
}
}


Expand Down
8 changes: 8 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,5 +292,13 @@ function xmldb_moodleoverflow_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2023040400, 'moodleoverflow');
}

if ($oldversion < 2024072600) {
require_once($CFG->dirroot . '/mod/moodleoverflow/db/upgradelib.php');

mod_moodleoverflow_move_draftfiles_to_permanent_filearea();

upgrade_mod_savepoint(true, 2024072600, 'moodleoverflow');
}

return true;
}
Loading

0 comments on commit 7aa4e2a

Please sign in to comment.