MDL-86254 core_comment: deprecate locallib classes

This commit is contained in:
ferran
2025-08-22 09:48:03 +08:00
committed by Adrian Greeve
parent a462603ea5
commit 0fd34211df
5 changed files with 84 additions and 9 deletions
@@ -0,0 +1,8 @@
issueNumber: MDL-86254
notes:
core_comment:
- message: >-
The `public/comment/locallib.php` file and the `comment_manager` class
have been deprecated. All related functionality should now be accessed
via the `\core_comment\manager` class.
type: deprecated
+50
View File
@@ -1072,6 +1072,56 @@ class manager {
return ($hascapability || ($owncomment && $this->can_post()));
}
/**
* Get comments created since a given time.
*
* @param stdClass $course course object
* @param stdClass $context context object
* @param string $component component name
* @param int $since the time to check
* @param \cm_info|null $cm optional course module object
* @return array list of comments db records since the given timelimit
* @since Moodle 3.2
*/
public static function get_component_comments_since(
stdClass $course,
stdClass $context,
string $component,
int $since,
?\cm_info $cm = null
): array {
global $DB;
$result = [];
$where = 'contextid = ? AND component = ? AND timecreated > ?';
$comments = $DB->get_records_select('comments', $where, [$context->id, $component, $since]);
// Check item by item if we have permissions.
$managersviewstatus = [];
foreach ($comments as $comment) {
$cachedkey = $comment->commentarea . '/' . $comment->itemid;
if (!isset($managersviewstatus[$cachedkey])) {
$args = (object)[
'area' => $comment->commentarea,
'itemid' => $comment->itemid,
'context' => $context,
'course' => $course,
'client_id' => 0,
'component' => $component,
'cm' => $cm,
];
$manager = new self($args);
$managersviewstatus[$cachedkey] = $manager->can_view();
}
if ($managersviewstatus[$cachedkey]) {
$result[$comment->id] = $comment;
}
}
return $result;
}
/**
* Returns the component associated with the comment.
*
+24
View File
@@ -15,12 +15,20 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') || die();
debugging(
'This file has been deprecated. Please, use \core_comment\manager instead',
DEBUG_DEVELOPER,
);
/**
* comment_manager is helper class to manage moodle comments in admin page (Reports->Comments)
*
* @package core_comment
* @copyright 2010 Dongsheng Cai {@link http://dongsheng.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @todo Remove this class and the file in Moodle 6.0 (MDL-86257)
*/
class comment_manager {
@@ -48,8 +56,16 @@ class comment_manager {
/**
* Constructs the comment_manage object
*/
#[\core\attribute\deprecated(
replacement: 'core_comment\manager',
since: '5.1',
mdl: 'MDL-86254',
)]
public function __construct() {
global $CFG;
\core\deprecation::emit_deprecation(__FUNCTION__);
$this->perpage = $CFG->commentsperpage;
}
@@ -245,10 +261,18 @@ class comment_manager {
* @param stdClass|\cm_info|null $cm course module object
* @return array list of comments db records since the given timelimit
* @since Moodle 3.2
*
*/
#[\core\attribute\deprecated(
replacement: 'core_comment\manager::get_component_comments_since',
since: '5.1',
mdl: 'MDL-86254',
)]
public function get_component_comments_since($course, $context, $component, $since, $cm = null) {
global $DB;
\core\deprecation::emit_deprecation(__FUNCTION__);
$commentssince = array();
$where = 'contextid = ? AND component = ? AND timecreated > ?';
$comments = $DB->get_records_select('comments', $where, array($context->id, $component, $since));
@@ -23,11 +23,6 @@
*/
namespace core_comment\privacy;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/comment/locallib.php');
use core_privacy\local\request\approved_userlist;
use core_privacy\tests\provider_testcase;
use core_privacy\tests\request\approved_contextlist;
+2 -4
View File
@@ -4426,10 +4426,8 @@ function course_check_module_updates_since($cm, $from, $fileareas = array(), $fi
// Check comments.
if (plugin_supports('mod', $cm->modname, FEATURE_COMMENT) and (empty($filter) or in_array('comments', $filter))) {
$updates->comments = (object) array('updated' => false);
require_once($CFG->dirroot . '/comment/locallib.php');
$manager = new comment_manager();
$comments = $manager->get_component_comments_since($course, $context, $component, $from, $cm);
$updates->comments = (object) ['updated' => false];
$comments = core_comment\manager::get_component_comments_since($course, $context, $component, $from, $cm);
if (!empty($comments)) {
$updates->comments->updated = true;
$updates->comments->itemids = array_keys($comments);