Skip to content

Saving content

Sebastian Rettig edited this page Sep 4, 2019 · 1 revision
  • The entry point is in the CMS plugin. (e.g. in Moodle: lib.php:hvp_save_content)
  • Body of request: { params: { metadata: { title: string, course: ???, intro: ???, introformat: ??? }, // things like author information, name of content etc. params: any // the parameter object of the main content type (as in content.json) }, name?: string, library: string, // (string with library name/version) h5paction: "upload" | undefined // differentiates between uploads and new creations/edits id?: ???, // (optional) id of existing content type disable?: any // disables things like frame, download, embed, copyright, about, ... }
  • When uploading a file:
    • storage->savePackage (...)
    • return contentId
  • When new or edited:
    • Find out if edit (by checking if id is set)
      • Yes? Get old library name/version and params of
    • add appropriate libraryId to library
    • call core->saveContent(...) (returns id) (implementation in h5p-php-library/h5p.classes.php:H5PCore->saveContent)
      • check if id is set
        • Yes? --> call updateContent (implementation in plugin, e.g. h5p-moodle/framework.php:framework->insertContent) calls updateContent
        • No? --> call insertContent (and set id) (implementation in plugin, e.g. h5p-moodle/framework.php:framework->insertContent) saves data received in a database record (wtih timestamp of modification) log create/update/upload
      • reset content user data for id (implementation in plugin, e.g. h5p-moodle/framework.php:framework->resetContentUserData)
        • set DB entry of user data of contentId to "data = RESET" (if delete_on_content_change is 1)
    • call editor->processParamers(...), also with old library name & params (to move uploaded files/images and determine content dependencies (??? Why even care about content dependencies? They are not used anywhere!))
      • call processFields with main library as starting point with NEW params
        • processFields: library?: load library semantics and calls processSemantics (because it's called as a library first) (calls processField for each entry of the semantics together with matching field in the params) file/image?: calls processFile (images also have a nested property "originalImage"; call processFile for it, too) video/audio?: call processFile for each array entry group?: if is not subcontent (isSubcontent in params is NOT set to true) and there is only one entry in fields: flatten it or something??? list: call processFields for each array entry
        • processFile: skip URLs with http(s):// remove suffix "#tmp" clone content file if the path relative (???) and update path in params check if file exists in content folder yes?: mark file to keep (storage->keepFile) no?: copy from editor tmp dir to content folder (don't remove it (reason: "in case someone has copied it", automatically deleted after 24h)) append path to file list
      • call processSemantics with OLD library name/version and OLD params (when updating)
      • delete content files that were removed in the change
    • return new id