Skip to Content
PluginsShort LinksArchitecture

Architecture

Data Flow

  1. User submits form -> api::create() called.
  2. Resolves code length from type (6/12/12).
  3. If Unguessable, generates 16-char base62 code.
  4. DB transaction: create link persistent (fires link_created event), attach tags.
  5. Calls \core\shortlink::create_public_shortlink() for actual short URL.
  6. If Unguessable, appends ?c=<code> to short URL.
  7. Updates link record with final URL. Commit.
  1. Moodle core shortlink system calls shortlink_handler::process_shortlink('url', $id).
  2. Looks up link by ID.
  3. If Unguessable, checks ?c= param matches stored code.
  4. Fires link_redirected event.
  5. Redirects to destination URL.
  1. Route /{link}/delete -> confirmation -> sesskey check.
  2. Deletes persistent (fires link_deleted event).
  3. Redirects home.

Database

Table local_shortlinks:

FieldTypeNotes
idINT PKAuto
useridINT FKOwner
destinationurlTEXTTarget URL
shorturlTEXTGenerated short URL
unguessablecodeCHAR(128)Nullable, random 16-char base62
timecreatedINTTimestamp
timemodifiedINTTimestamp
usermodifiedINT FKLast modifier

Router

Uses Moodle’s router with PHP 8 attributes:

RouteControllerDescription
GET ''links_controller::home()Home page with report
GET|POST '/{link}/delete'links_controller::delete_link()Delete confirmation

Shim route /redirect/delete?id=X bridges report builder actions (query params) to the path-param-based controller.

Events

All extend core\event\base:

EventCRUDFired
link_createdcAfter link saved
link_updateduAfter link updated
link_deleteddAfter link deleted
link_redirectedrWhen short link is visited

Handler

shortlink_handler implements core\shortlink_handler_interface. Processes type url. Resolves link ID -> destination URL.

Observer

observers::user_deleted on core\event\user_deleted:

  • Sets usermodified=0 for deleted user’s edits.
  • Deletes all links owned by deleted user.

Report Builder

System report links with entity link:

  • Columns: shorturl, destinationurl, timecreated.
  • Filters: timecreated, userid, tags.
  • Conditions: userid = current user.
  • Actions: delete with modal confirmation.
  • Favicons from DuckDuckGo (icons.duckduckgo.com/ip3/).

Tags

Tag area registered for local_shortlinks itemtype. Callback local_shortlinks_get_tagged_links() is a stub (not yet implemented).