Kirby w Database - Files / Status Issue

Hello,

I followed this receipe to get contents from a database. Its all working great, but i do have some trouble with file-uploads and changing page-status.

I have an image fields in my pages. The image URL are saved correctly in the DB. And they are uploaded in the content folder like so

content
 - venues
   - 0_VenueOne
   - 0_VenueTwo
  (....)

Now when i change the Status to Unlisted or Draft, the status field in the DB gets updated and also the whole Kirby-Mechanism (Icon changes etc). is working fine.

But the images are gone in the panel because (obvioulsy) the path changed. For unlisted pages i would need to remove the leading β€˜0_’, and for drafts i would need the β€˜_drafts’ folder.

Iam wondering what page methods needed to be change in order to sync changes in the DB with the filesystem ?

my parent model

class VenuesPage extends Kirby\Cms\Page {

public function children() {        
    $venues = [];        
    foreach (Db::select('venues') as $venue) {

        $venues[] = [
            'slug'     => $venue->slug(),
            'num'      => $venue->status() === 'listed' ? 0 : null,
            'template' => 'venue',
            'model'    => 'venue',
            'content'  => [
                'title'  => $venue->title(),
                'status' => is_null($venue->status()) ? 'draft' : $venue->status(),
                (...)
            ]
        ];
    }
    return Pages::factory($venues, $this);
  }
}

and the page model:

class VenuePage extends Kirby\Cms\Page
{

protected function changeStatusToDraft()
{
    $data['status'] = 'null';

    if ($venue = Db::first('venues', '*', ['slug' => $this->slug()])) {
        return Db::update('venues', $data, ['slug' => $this->slug()]);
    }

    return $this;
}


protected function changeStatusToListed(int $position = null)
{
    // create a sorting number for the page
    $num = $this->createNum($position);

    // don't sort if not necessary
    if ($this->status() === 'listed' && $num === $this->num()) {
        return $this;
    }

    $data['status'] = 'listed';

    if ($venue = Db::first('venues', '*', ['slug' => $this->slug()])) {
        return Db::update('venues', $data, ['slug' => $this->slug()]);
    }

    if ($this->blueprint()->num() === 'default') {
        $this->resortSiblingsAfterListing($num);
    }

    return $this;
}


protected function changeStatusToUnlisted()
{
    if ($this->status() === 'unlisted') {
        return $this;
    }

    $data['status'] = 'unlisted';

    if ($venue = Db::first('venues', '*', ['slug' => $this->slug()])) {
        return Db::update('venues', $data, ['slug' => $this->slug()]);
    }

    $this->resortSiblingsAfterUnlisting();

    return $this;
}


public function changeTitle(string $title, string $languageCode = null)
{
    $data['title'] = $title;

    if ($venue = Db::first('venues', '*', ['slug' => $this->slug()])) {
        if (Db::update('venues', $data, ['slug' => $this->slug()])) {
            return $this;
        };
    } 
    return $this;
}

public function delete(bool $force = false): bool
{
    return Db::delete('venues', ['slug' => $this->slug()]);
}

public function isDraft(): bool
{
    return in_array($this->content()->status(), ['listed', 'unlisted']) === false;
}

public function writeContent(array $data, string $languageCode = null): bool
{
    unset($data['title']);

    if ($venue = Db::first('venues', '*', ['slug' => $this->slug()])) {
        return Db::update('venues', $data, ['slug' => $this->slug()]);
    } else {
        $data['slug'] = $this->slug();
        return Db::insert('venues', $data);
    }

  }

}

Any help would be awesome, thank you !

I forgot: The Database Fields are

 ID (INT PRIMARY AI), 
 slug (VARCHAR UNIQUE), 
 status (VARCHAR) 
 title (VARCHAR )
 [and some more content fields]

And what do you store for the images?

In the blueprints the images are stored in a files field and in the database in a VARCHAR field.

the DB fields look like this:
- venues/VenueOne/image.jpg