Exemple #1
0
 /**
  * Test deleting a group of tag instances.
  */
 public function test_tag_bulk_delete_instances()
 {
     global $DB;
     $task = new \core\task\tag_cron_task();
     // Setup.
     $user = $this->getDataGenerator()->create_user();
     $course = $this->getDataGenerator()->create_course();
     $context = context_course::instance($course->id);
     // Create some tag instances.
     for ($i = 0; $i < 10; $i++) {
         $tag = $this->getDataGenerator()->create_tag(array('userid' => $user->id));
         core_tag_tag::add_item_tag('core', 'course', $course->id, $context, $tag->rawname);
     }
     // Get tag instances. tag name and rawname are required for the event fired in this function.
     $sql = "SELECT ti.*, t.name, t.rawname\n                  FROM {tag_instance} ti\n                  JOIN {tag} t ON t.id = ti.tagid";
     $taginstances = $DB->get_records_sql($sql);
     $this->assertCount(10, $taginstances);
     // Run the function.
     $task->bulk_delete_instances($taginstances);
     // Make sure they are gone.
     $instancecount = $DB->count_records('tag_instance');
     $this->assertEquals(0, $instancecount);
 }
Exemple #2
0
/**
 * This function will delete numerous tag instances efficiently.
 * This removes tag instances only. It doesn't check to see if it is the last use of a tag.
 *
 * @deprecated since 3.1
 * @param array $instances An array of tag instance objects with the addition of the tagname and tagrawname
 *        (used for recording a delete event).
 */
function tag_bulk_delete_instances($instances)
{
    debugging('Method tag_bulk_delete_instances() is deprecated, ' . 'use \\core\\task\\tag_cron_task::bulk_delete_instances()', DEBUG_DEVELOPER);
    $task = new \core\task\tag_cron_task();
    return $task->bulk_delete_instances($instances);
}