How to handle files when working with a database?

I run into problems with file uploads in a database-driven setup. For a clean start I followed the guide Content from a database.

When uploading a file, Kirby does write the correct URL into the database. To store the file itself, it creates a folder in the file system.

Problems occur on standard page operations like changing status, changing slug or delete: Changes are performed only in the database, not in the file system (because the custom page methods from the page model only affect the database, not the file system).

In my usecase, I’d like to store files outside the database, maybe even on a remote cloud server.

Can the page model be extended to achieve this?
Any recent ideas on using hooks?

Thank you.

In this case you probably have to update the folder in the filesystem in addition to updating the database column.

Thank you. I suppose this means to add the respective functions to the page model, right? Could you please be more specific on which functions are needed here?

More generally asking, are there further resources on how to extend the functionality when working with a database? The guides in the docs are excellent, yet pretty basic. I find it difficult to understand which functions are required for which operations.

Basically all functions that that modify the page object: changeSlug(), changeTitle(), changeStatus(), changeNum(), changeTemplate(), etc. depending on what is relevant in your context.

I haven’t worked with files and content from a database yet, though. But if you change the page slug in the database, you have to keep that in sync with the names of the local folders. And also the file url you store in the database will no longer be correct if you change the page slug.

Just to make sure I understand the concept correctly: In my custom page model, I would combine the native Kirby functions to modify the page object with the code to handle the database? To put it more specific, I would copy the functions I need from kirby/src/Cms/PageActions.php to my page model, customize them and add the code to handle the database?

If so, I must say it does feel a bit hacky (redundancy and maintenance). Isn’t there a way to extend page actions rather than overwriting?