/** * Delete a field completely */ public function delete() { // Delete the comments. $params = array('contextid' => $this->df->context->id, 'commentarea' => $this->name); comment::delete_comments($params); return parent::delete(); }
function admin_purge_related($table, $id) { $ns = e107::getRender(); $tp = e107::getParser(); $msg = ""; $tp->parseTemplate(""); // Delete any related comments require_once e_HANDLER . "comment_class.php"; $_com = new comment(); $num = $_com->delete_comments($table, $id); if ($num) { $msg .= $num . " " . LAN_COMMENTS . " " . LAN_DELETED . "<br />"; } // Delete any related ratings require_once e_HANDLER . "rate_class.php"; $_rate = new rater(); $num = $_rate->delete_ratings($table, $id); if ($num) { $msg .= LAN_RATING . " " . LAN_DELETED . "<br />"; } if ($msg) { $ns->tablerender(LAN_DELETE, $msg); } }
/** * Delete all data linked to content, do not delete the context record itself */ public function delete_content() { global $CFG, $DB; blocks_delete_all_for_context($this->_id); filter_delete_all_for_context($this->_id); require_once $CFG->dirroot . '/comment/lib.php'; comment::delete_comments(array('contextid' => $this->_id)); require_once $CFG->dirroot . '/rating/lib.php'; $delopt = new stdclass(); $delopt->contextid = $this->_id; $rm = new rating_manager(); $rm->delete_ratings($delopt); // delete all files attached to this context $fs = get_file_storage(); $fs->delete_area_files($this->_id); // delete all advanced grading data attached to this context require_once $CFG->dirroot . '/grade/grading/lib.php'; grading_manager::delete_all_for_context($this->_id); // now delete stuff from role related tables, role_unassign_all // and unenrol should be called earlier to do proper cleanup $DB->delete_records('role_assignments', array('contextid' => $this->_id)); $DB->delete_records('role_capabilities', array('contextid' => $this->_id)); $DB->delete_records('role_names', array('contextid' => $this->_id)); }
/** * Clear a course out completely, deleting all content but don't delete the course itself. * * This function does not verify any permissions. * * Please note this function also deletes all user enrolments, * enrolment instances and role assignments by default. * * $options: * - 'keep_roles_and_enrolments' - false by default * - 'keep_groups_and_groupings' - false by default * * @param int $courseid The id of the course that is being deleted * @param bool $showfeedback Whether to display notifications of each action the function performs. * @param array $options extra options * @return bool true if all the removals succeeded. false if there were any failures. If this * method returns false, some of the removals will probably have succeeded, and others * failed, but you have no way of knowing which. */ function remove_course_contents($courseid, $showfeedback = true, array $options = null) { global $CFG, $DB, $OUTPUT; require_once $CFG->libdir . '/badgeslib.php'; require_once $CFG->libdir . '/completionlib.php'; require_once $CFG->libdir . '/questionlib.php'; require_once $CFG->libdir . '/gradelib.php'; require_once $CFG->dirroot . '/group/lib.php'; require_once $CFG->dirroot . '/comment/lib.php'; require_once $CFG->dirroot . '/rating/lib.php'; require_once $CFG->dirroot . '/notes/lib.php'; // Handle course badges. badges_handle_course_deletion($courseid); // NOTE: these concatenated strings are suboptimal, but it is just extra info... $strdeleted = get_string('deleted') . ' - '; // Some crazy wishlist of stuff we should skip during purging of course content. $options = (array) $options; $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); $coursecontext = context_course::instance($courseid); $fs = get_file_storage(); // Delete course completion information, this has to be done before grades and enrols. $cc = new completion_info($course); $cc->clear_criteria(); if ($showfeedback) { echo $OUTPUT->notification($strdeleted . get_string('completion', 'completion'), 'notifysuccess'); } // Remove all data from gradebook - this needs to be done before course modules // because while deleting this information, the system may need to reference // the course modules that own the grades. remove_course_grades($courseid, $showfeedback); remove_grade_letters($coursecontext, $showfeedback); // Delete course blocks in any all child contexts, // they may depend on modules so delete them first. $childcontexts = $coursecontext->get_child_contexts(); // Returns all subcontexts since 2.2. foreach ($childcontexts as $childcontext) { blocks_delete_all_for_context($childcontext->id); } unset($childcontexts); blocks_delete_all_for_context($coursecontext->id); if ($showfeedback) { echo $OUTPUT->notification($strdeleted . get_string('type_block_plural', 'plugin'), 'notifysuccess'); } // Get the list of all modules that are properly installed. $allmodules = $DB->get_records_menu('modules', array(), '', 'name, id'); // Delete every instance of every module, // this has to be done before deleting of course level stuff. $locations = core_component::get_plugin_list('mod'); foreach ($locations as $modname => $moddir) { if ($modname === 'NEWMODULE') { continue; } if (array_key_exists($modname, $allmodules)) { $sql = "SELECT cm.*, m.id AS modinstance, m.name, '{$modname}' AS modname\n FROM {" . $modname . "} m\n LEFT JOIN {course_modules} cm ON cm.instance = m.id AND cm.module = :moduleid\n WHERE m.course = :courseid"; $instances = $DB->get_records_sql($sql, array('courseid' => $course->id, 'modulename' => $modname, 'moduleid' => $allmodules[$modname])); include_once "{$moddir}/lib.php"; // Shows php warning only if plugin defective. $moddelete = $modname . '_delete_instance'; // Delete everything connected to an instance. $moddeletecourse = $modname . '_delete_course'; // Delete other stray stuff (uncommon). if ($instances) { foreach ($instances as $cm) { if ($cm->id) { // Delete activity context questions and question categories. question_delete_activity($cm, $showfeedback); // Notify the competency subsystem. \core_competency\api::hook_course_module_deleted($cm); } if (function_exists($moddelete)) { // This purges all module data in related tables, extra user prefs, settings, etc. $moddelete($cm->modinstance); } else { // NOTE: we should not allow installation of modules with missing delete support! debugging("Defective module '{$modname}' detected when deleting course contents: missing function {$moddelete}()!"); $DB->delete_records($modname, array('id' => $cm->modinstance)); } if ($cm->id) { // Delete cm and its context - orphaned contexts are purged in cron in case of any race condition. context_helper::delete_instance(CONTEXT_MODULE, $cm->id); $DB->delete_records('course_modules', array('id' => $cm->id)); } } } if (function_exists($moddeletecourse)) { // Execute optional course cleanup callback. Deprecated since Moodle 3.2. TODO MDL-53297 remove in 3.6. debugging("Callback delete_course is deprecated. Function {$moddeletecourse} should be converted " . 'to observer of event \\core\\event\\course_content_deleted', DEBUG_DEVELOPER); $moddeletecourse($course, $showfeedback); } if ($instances and $showfeedback) { echo $OUTPUT->notification($strdeleted . get_string('pluginname', $modname), 'notifysuccess'); } } else { // Ooops, this module is not properly installed, force-delete it in the next block. } } // We have tried to delete everything the nice way - now let's force-delete any remaining module data. // Remove all data from availability and completion tables that is associated // with course-modules belonging to this course. Note this is done even if the // features are not enabled now, in case they were enabled previously. $DB->delete_records_select('course_modules_completion', 'coursemoduleid IN (SELECT id from {course_modules} WHERE course=?)', array($courseid)); // Remove course-module data that has not been removed in modules' _delete_instance callbacks. $cms = $DB->get_records('course_modules', array('course' => $course->id)); $allmodulesbyid = array_flip($allmodules); foreach ($cms as $cm) { if (array_key_exists($cm->module, $allmodulesbyid)) { try { $DB->delete_records($allmodulesbyid[$cm->module], array('id' => $cm->instance)); } catch (Exception $e) { // Ignore weird or missing table problems. } } context_helper::delete_instance(CONTEXT_MODULE, $cm->id); $DB->delete_records('course_modules', array('id' => $cm->id)); } if ($showfeedback) { echo $OUTPUT->notification($strdeleted . get_string('type_mod_plural', 'plugin'), 'notifysuccess'); } // Cleanup the rest of plugins. Deprecated since Moodle 3.2. TODO MDL-53297 remove in 3.6. $cleanuplugintypes = array('report', 'coursereport', 'format'); $callbacks = get_plugins_with_function('delete_course', 'lib.php'); foreach ($cleanuplugintypes as $type) { if (!empty($callbacks[$type])) { foreach ($callbacks[$type] as $pluginfunction) { debugging("Callback delete_course is deprecated. Function {$pluginfunction} should be converted " . 'to observer of event \\core\\event\\course_content_deleted', DEBUG_DEVELOPER); $pluginfunction($course->id, $showfeedback); } if ($showfeedback) { echo $OUTPUT->notification($strdeleted . get_string('type_' . $type . '_plural', 'plugin'), 'notifysuccess'); } } } // Delete questions and question categories. question_delete_course($course, $showfeedback); if ($showfeedback) { echo $OUTPUT->notification($strdeleted . get_string('questions', 'question'), 'notifysuccess'); } // Make sure there are no subcontexts left - all valid blocks and modules should be already gone. $childcontexts = $coursecontext->get_child_contexts(); // Returns all subcontexts since 2.2. foreach ($childcontexts as $childcontext) { $childcontext->delete(); } unset($childcontexts); // Remove all roles and enrolments by default. if (empty($options['keep_roles_and_enrolments'])) { // This hack is used in restore when deleting contents of existing course. role_unassign_all(array('contextid' => $coursecontext->id, 'component' => ''), true); enrol_course_delete($course); if ($showfeedback) { echo $OUTPUT->notification($strdeleted . get_string('type_enrol_plural', 'plugin'), 'notifysuccess'); } } // Delete any groups, removing members and grouping/course links first. if (empty($options['keep_groups_and_groupings'])) { groups_delete_groupings($course->id, $showfeedback); groups_delete_groups($course->id, $showfeedback); } // Filters be gone! filter_delete_all_for_context($coursecontext->id); // Notes, you shall not pass! note_delete_all($course->id); // Die comments! comment::delete_comments($coursecontext->id); // Ratings are history too. $delopt = new stdclass(); $delopt->contextid = $coursecontext->id; $rm = new rating_manager(); $rm->delete_ratings($delopt); // Delete course tags. core_tag_tag::remove_all_item_tags('core', 'course', $course->id); // Notify the competency subsystem. \core_competency\api::hook_course_deleted($course); // Delete calendar events. $DB->delete_records('event', array('courseid' => $course->id)); $fs->delete_area_files($coursecontext->id, 'calendar'); // Delete all related records in other core tables that may have a courseid // This array stores the tables that need to be cleared, as // table_name => column_name that contains the course id. $tablestoclear = array('backup_courses' => 'courseid', 'user_lastaccess' => 'courseid'); foreach ($tablestoclear as $table => $col) { $DB->delete_records($table, array($col => $course->id)); } // Delete all course backup files. $fs->delete_area_files($coursecontext->id, 'backup'); // Cleanup course record - remove links to deleted stuff. $oldcourse = new stdClass(); $oldcourse->id = $course->id; $oldcourse->summary = ''; $oldcourse->cacherev = 0; $oldcourse->legacyfiles = 0; if (!empty($options['keep_groups_and_groupings'])) { $oldcourse->defaultgroupingid = 0; } $DB->update_record('course', $oldcourse); // Delete course sections. $DB->delete_records('course_sections', array('course' => $course->id)); // Delete legacy, section and any other course files. $fs->delete_area_files($coursecontext->id, 'course'); // Files from summary and section. // Delete all remaining stuff linked to context such as files, comments, ratings, etc. if (empty($options['keep_roles_and_enrolments']) and empty($options['keep_groups_and_groupings'])) { // Easy, do not delete the context itself... $coursecontext->delete_content(); } else { // Hack alert!!!! // We can not drop all context stuff because it would bork enrolments and roles, // there might be also files used by enrol plugins... } // Delete legacy files - just in case some files are still left there after conversion to new file api, // also some non-standard unsupported plugins may try to store something there. fulldelete($CFG->dataroot . '/' . $course->id); // Delete from cache to reduce the cache size especially makes sense in case of bulk course deletion. $cachemodinfo = cache::make('core', 'coursemodinfo'); $cachemodinfo->delete($courseid); // Trigger a course content deleted event. $event = \core\event\course_content_deleted::create(array('objectid' => $course->id, 'context' => $coursecontext, 'other' => array('shortname' => $course->shortname, 'fullname' => $course->fullname, 'options' => $options))); $event->add_record_snapshot('course', $course); $event->trigger(); return true; }
/** * Clear a course out completely, deleting all content * but don't delete the course itself. * This function does not verify any permissions. * * Please note this function also deletes all user enrolments, * enrolment instances and role assignments by default. * * $options: * - 'keep_roles_and_enrolments' - false by default * - 'keep_groups_and_groupings' - false by default * * @param int $courseid The id of the course that is being deleted * @param bool $showfeedback Whether to display notifications of each action the function performs. * @param array $options extra options * @return bool true if all the removals succeeded. false if there were any failures. If this * method returns false, some of the removals will probably have succeeded, and others * failed, but you have no way of knowing which. */ function remove_course_contents($courseid, $showfeedback = true, array $options = null) { global $CFG, $DB, $OUTPUT; require_once $CFG->libdir . '/completionlib.php'; require_once $CFG->libdir . '/questionlib.php'; require_once $CFG->libdir . '/gradelib.php'; require_once $CFG->dirroot . '/group/lib.php'; require_once $CFG->dirroot . '/tag/coursetagslib.php'; require_once $CFG->dirroot . '/comment/lib.php'; require_once $CFG->dirroot . '/rating/lib.php'; // NOTE: these concatenated strings are suboptimal, but it is just extra info... $strdeleted = get_string('deleted') . ' - '; // Some crazy wishlist of stuff we should skip during purging of course content $options = (array) $options; $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST); $coursecontext = context_course::instance($courseid); $fs = get_file_storage(); // Delete course completion information, this has to be done before grades and enrols $cc = new completion_info($course); $cc->clear_criteria(); if ($showfeedback) { echo $OUTPUT->notification($strdeleted . get_string('completion', 'completion'), 'notifysuccess'); } // Remove all data from gradebook - this needs to be done before course modules // because while deleting this information, the system may need to reference // the course modules that own the grades. remove_course_grades($courseid, $showfeedback); remove_grade_letters($coursecontext, $showfeedback); // Delete course blocks in any all child contexts, // they may depend on modules so delete them first $childcontexts = $coursecontext->get_child_contexts(); // returns all subcontexts since 2.2 foreach ($childcontexts as $childcontext) { blocks_delete_all_for_context($childcontext->id); } unset($childcontexts); blocks_delete_all_for_context($coursecontext->id); if ($showfeedback) { echo $OUTPUT->notification($strdeleted . get_string('type_block_plural', 'plugin'), 'notifysuccess'); } // Delete every instance of every module, // this has to be done before deleting of course level stuff $locations = get_plugin_list('mod'); foreach ($locations as $modname => $moddir) { if ($modname === 'NEWMODULE') { continue; } if ($module = $DB->get_record('modules', array('name' => $modname))) { include_once "{$moddir}/lib.php"; // Shows php warning only if plugin defective $moddelete = $modname . '_delete_instance'; // Delete everything connected to an instance $moddeletecourse = $modname . '_delete_course'; // Delete other stray stuff (uncommon) if ($instances = $DB->get_records($modname, array('course' => $course->id))) { foreach ($instances as $instance) { if ($cm = get_coursemodule_from_instance($modname, $instance->id, $course->id)) { /// Delete activity context questions and question categories question_delete_activity($cm, $showfeedback); } if (function_exists($moddelete)) { // This purges all module data in related tables, extra user prefs, settings, etc. $moddelete($instance->id); } else { // NOTE: we should not allow installation of modules with missing delete support! debugging("Defective module '{$modname}' detected when deleting course contents: missing function {$moddelete}()!"); $DB->delete_records($modname, array('id' => $instance->id)); } if ($cm) { // Delete cm and its context - orphaned contexts are purged in cron in case of any race condition context_helper::delete_instance(CONTEXT_MODULE, $cm->id); $DB->delete_records('course_modules', array('id' => $cm->id)); } } } if (function_exists($moddeletecourse)) { // Execute ptional course cleanup callback $moddeletecourse($course, $showfeedback); } if ($instances and $showfeedback) { echo $OUTPUT->notification($strdeleted . get_string('pluginname', $modname), 'notifysuccess'); } } else { // Ooops, this module is not properly installed, force-delete it in the next block } } // We have tried to delete everything the nice way - now let's force-delete any remaining module data // Remove all data from availability and completion tables that is associated // with course-modules belonging to this course. Note this is done even if the // features are not enabled now, in case they were enabled previously. $DB->delete_records_select('course_modules_completion', 'coursemoduleid IN (SELECT id from {course_modules} WHERE course=?)', array($courseid)); $DB->delete_records_select('course_modules_availability', 'coursemoduleid IN (SELECT id from {course_modules} WHERE course=?)', array($courseid)); // Remove course-module data. $cms = $DB->get_records('course_modules', array('course' => $course->id)); foreach ($cms as $cm) { if ($module = $DB->get_record('modules', array('id' => $cm->module))) { try { $DB->delete_records($module->name, array('id' => $cm->instance)); } catch (Exception $e) { // Ignore weird or missing table problems } } context_helper::delete_instance(CONTEXT_MODULE, $cm->id); $DB->delete_records('course_modules', array('id' => $cm->id)); } if ($showfeedback) { echo $OUTPUT->notification($strdeleted . get_string('type_mod_plural', 'plugin'), 'notifysuccess'); } // Cleanup the rest of plugins $cleanuplugintypes = array('report', 'coursereport', 'format'); foreach ($cleanuplugintypes as $type) { $plugins = get_plugin_list_with_function($type, 'delete_course', 'lib.php'); foreach ($plugins as $plugin => $pluginfunction) { $pluginfunction($course->id, $showfeedback); } if ($showfeedback) { echo $OUTPUT->notification($strdeleted . get_string('type_' . $type . '_plural', 'plugin'), 'notifysuccess'); } } // Delete questions and question categories question_delete_course($course, $showfeedback); if ($showfeedback) { echo $OUTPUT->notification($strdeleted . get_string('questions', 'question'), 'notifysuccess'); } // Make sure there are no subcontexts left - all valid blocks and modules should be already gone $childcontexts = $coursecontext->get_child_contexts(); // returns all subcontexts since 2.2 foreach ($childcontexts as $childcontext) { $childcontext->delete(); } unset($childcontexts); // Remove all roles and enrolments by default if (empty($options['keep_roles_and_enrolments'])) { // this hack is used in restore when deleting contents of existing course role_unassign_all(array('contextid' => $coursecontext->id, 'component' => ''), true); enrol_course_delete($course); if ($showfeedback) { echo $OUTPUT->notification($strdeleted . get_string('type_enrol_plural', 'plugin'), 'notifysuccess'); } } // Delete any groups, removing members and grouping/course links first. if (empty($options['keep_groups_and_groupings'])) { groups_delete_groupings($course->id, $showfeedback); groups_delete_groups($course->id, $showfeedback); } // filters be gone! filter_delete_all_for_context($coursecontext->id); // die comments! comment::delete_comments($coursecontext->id); // ratings are history too $delopt = new stdclass(); $delopt->contextid = $coursecontext->id; $rm = new rating_manager(); $rm->delete_ratings($delopt); // Delete course tags coursetag_delete_course_tags($course->id, $showfeedback); // Delete calendar events $DB->delete_records('event', array('courseid' => $course->id)); $fs->delete_area_files($coursecontext->id, 'calendar'); // Delete all related records in other core tables that may have a courseid // This array stores the tables that need to be cleared, as // table_name => column_name that contains the course id. $tablestoclear = array('log' => 'course', 'backup_courses' => 'courseid', 'user_lastaccess' => 'courseid'); foreach ($tablestoclear as $table => $col) { $DB->delete_records($table, array($col => $course->id)); } // delete all course backup files $fs->delete_area_files($coursecontext->id, 'backup'); // cleanup course record - remove links to deleted stuff $oldcourse = new stdClass(); $oldcourse->id = $course->id; $oldcourse->summary = ''; $oldcourse->modinfo = NULL; $oldcourse->legacyfiles = 0; $oldcourse->enablecompletion = 0; if (!empty($options['keep_groups_and_groupings'])) { $oldcourse->defaultgroupingid = 0; } $DB->update_record('course', $oldcourse); // Delete course sections and availability options. $DB->delete_records_select('course_sections_availability', 'coursesectionid IN (SELECT id from {course_sections} WHERE course=?)', array($course->id)); $DB->delete_records('course_sections', array('course' => $course->id)); // delete legacy, section and any other course files $fs->delete_area_files($coursecontext->id, 'course'); // files from summary and section // Delete all remaining stuff linked to context such as files, comments, ratings, etc. if (empty($options['keep_roles_and_enrolments']) and empty($options['keep_groups_and_groupings'])) { // Easy, do not delete the context itself... $coursecontext->delete_content(); } else { // Hack alert!!!! // We can not drop all context stuff because it would bork enrolments and roles, // there might be also files used by enrol plugins... } // Delete legacy files - just in case some files are still left there after conversion to new file api, // also some non-standard unsupported plugins may try to store something there fulldelete($CFG->dataroot . '/' . $course->id); // Finally trigger the event $course->context = $coursecontext; // you can not access context in cron event later after course is deleted $course->options = $options; // not empty if we used any crazy hack events_trigger('course_content_removed', $course); return true; }
public function delete($options = array()) { global $DB; $coll = $this->get_collection(); $params = array('context' => $coll->context, 'objectid' => $this->id); if (!empty($options['nosync'])) { $params['other']['nosync'] = true; } $event = \mod_mediagallery\event\gallery_deleted::create($params); $event->add_record_snapshot('mediagallery_gallery', $this->record); $event->trigger(); // Delete all items and then the gallery. item::delete_all_by_gallery($this->record->id); \comment::delete_comments(array('commentarea' => 'gallery', 'itemid' => $this->record->id)); parent::delete(); return true; }
/** * Remove a context record and any dependent entries, * removes context from static context cache too * * @param int $level * @param int $instanceid * @param bool $deleterecord false means keep record for now * @return bool returns true or throws an exception */ function delete_context($contextlevel, $instanceid, $deleterecord = true) { global $DB, $ACCESSLIB_PRIVATE, $CFG; // do not use get_context_instance(), because the related object might not exist, // or the context does not exist yet and it would be created now if ($context = $DB->get_record('context', array('contextlevel' => $contextlevel, 'instanceid' => $instanceid))) { // delete these first because they might fetch the context and try to recreate it! blocks_delete_all_for_context($context->id); filter_delete_all_for_context($context->id); require_once $CFG->dirroot . '/comment/lib.php'; comment::delete_comments(array('contextid' => $context->id)); require_once $CFG->dirroot . '/rating/lib.php'; $delopt = new stdclass(); $delopt->contextid = $context->id; $rm = new rating_manager(); $rm->delete_ratings($delopt); // delete all files attached to this context $fs = get_file_storage(); $fs->delete_area_files($context->id); // now delete stuff from role related tables, role_unassign_all // and unenrol should be called earlier to do proper cleanup $DB->delete_records('role_assignments', array('contextid' => $context->id)); $DB->delete_records('role_capabilities', array('contextid' => $context->id)); $DB->delete_records('role_names', array('contextid' => $context->id)); // and finally it is time to delete the context record if requested if ($deleterecord) { $DB->delete_records('context', array('id' => $context->id)); // purge static context cache if entry present $ACCESSLIB_PRIVATE->contexcache->remove($context); } // do not mark dirty contexts if parents unknown if (!is_null($context->path) and $context->depth > 0) { mark_context_dirty($context->path); } } return true; }
/** * Delete the item and everything related to it. */ public function delete($options = array()) { global $DB; $params = array('context' => $this->get_context(), 'objectid' => $this->id); if (!empty($options['nosync'])) { $params['other']['nosync'] = true; } $event = \mod_mediagallery\event\item_deleted::create($params); $event->add_record_snapshot('mediagallery_item', $this->record); $event->trigger(); $fs = get_file_storage(); $fs->delete_area_files($this->get_context()->id, 'mod_mediagallery', 'item', $this->record->id); $fs->delete_area_files($this->get_context()->id, 'mod_mediagallery', 'lowres', $this->record->id); $fs->delete_area_files($this->get_context()->id, 'mod_mediagallery', 'thumbnail', $this->record->id); $DB->delete_records('mediagallery_userfeedback', array('itemid' => $this->record->id)); \comment::delete_comments(array('commentarea' => 'item', 'itemid' => $this->record->id)); return parent::delete(); }
function purgeComments($table) { global $sql, $tp; // Delete any related comments require_once e_HANDLER . "comment_class.php"; $_com = new comment(); $q = "SELECT DISTINCT " . MPREFIX . "comments.comment_item_id" . " FROM " . MPREFIX . "comments " . " WHERE (comment_type='{$table}')"; $text .= $q . '<br>'; $result = $sql->db_Query($q); $num_rows = mysql_numrows($result); for ($i = 0; $i < $num_rows; $i++) { $id = mysql_result($result, $i, "comment_item_id"); $text .= "comment id: {$id}<br>"; $num = $_com->delete_comments($table, $id); } }