Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-57476

Hooks into the file API

XMLWordPrintable

    • MOODLE_32_STABLE, MOODLE_33_STABLE, MOODLE_34_STABLE
    • MOODLE_34_STABLE
    • MDL-57476_file_callbacks
    • Hide

      Breakout your favorite editor. Add these lines to mod/forum/lib.php:

      function forum_create_file($file) {
          debugging('forum_create_file');
          var_dump($file);
      }
       
      function forum_update_file($newfile, $oldfile) {
          debugging('forum_update_file');
          if ($newfile->timemodified == $oldfile->timemodified) {
              throw new coding_exception('fail');
          }
          var_dump($newfile, $oldfile);
      }
       
      function forum_delete_file($file) {
          debugging('forum_delete_file');
          var_dump($file);
      }
      

      Drop the attached file_hooks_test.php into the root of your Moodle. Run file_hooks_test.php on the CLI, EG: php file_hooks_test.php

      You should see that the three forum hooks are called.

      Show
      Breakout your favorite editor. Add these lines to mod/forum/lib.php: function forum_create_file($file) { debugging('forum_create_file'); var_dump($file); }   function forum_update_file($newfile, $oldfile) { debugging('forum_update_file'); if ($newfile->timemodified == $oldfile->timemodified) { throw new coding_exception('fail'); } var_dump($newfile, $oldfile); }   function forum_delete_file($file) { debugging('forum_delete_file'); var_dump($file); } Drop the attached file_hooks_test.php into the root of your Moodle. Run file_hooks_test.php on the CLI, EG: php file_hooks_test.php You should see that the three forum hooks are called.

      We are building out a feature that we will eventually open source as a plugin, but it currently requires a patch into core Moodle. The patch is specifically around file deletion, EG: the plugin needs to know when any file has been deleted.

      Specifically, we had to patch \stored_file.delete method.

      We are hoping that we could get something into core that would be general purpose and likely have larger scope, EG: hooks for file updates, creates, etc.

      Unsure if these would be events or just API hooks. Looking for general feedback to see if this is at all possible or alternative solutions/proposals.

            brudinie guy thomas
            bushido Mark Nielsen
            Mark Nielsen Mark Nielsen
            Andrew Lyons Andrew Lyons
            Ankit Agarwal Ankit Agarwal
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.