eloquent-driver icon indicating copy to clipboard operation
eloquent-driver copied to clipboard

Delete old meta after move/rename

Open ryanmitchell opened this issue 1 year ago • 2 comments

Fixes: #70

ryanmitchell avatar Oct 07 '22 14:10 ryanmitchell

Will this also cover the issue for renaming assets?

leganz avatar Oct 07 '22 18:10 leganz

Should do.

ryanmitchell avatar Oct 07 '22 18:10 ryanmitchell

As mentioned in #80 - the writeMeta data will be called 3 times. only at the first time it has the metadata

leganz avatar Oct 25 '22 14:10 leganz

@ryanmitchell

If this line:

https://github.com/statamic/eloquent-driver/blob/de33af216ca369a3c4ccb07aa97fa176b7b97dc9/src/Assets/Asset.php#L63

is not set meta data won't be overwritten. But i think we could change the code to:

$handle = $this->container()->handle().'::'.$this->metaPath();
        if ($model = app('statamic.eloquent.assets.model')::where('handle', $handle)->first()) {
            $meta = $model->data;
        }
        else {
            $meta = $this->generateMeta();
        }   

I tested this and it will work with moveing/renaming

leganz avatar Oct 25 '22 15:10 leganz

Hmm that feels like an unnecessary db query - keen to avoid that. Does this change help?

ryanmitchell avatar Oct 25 '22 18:10 ryanmitchell

Hmm that feels like an unnecessary db query - keen to avoid that. Does this change help?

I am afraid it doesn't solve the issue right now. :/

leganz avatar Oct 25 '22 22:10 leganz

@ryanmitchell do we really need "$this->writeMeta($meta = $this->generateMeta());" in metaValue? I just removed it from the method (your latest version) and moving/renameing worked without losing meta data. eg:

private function metaValue($key)
    {
        $value = Arr::get($this->meta(), $key);

        if (! is_null($value)) {
            return $value;
        }

        Cache::forget($this->metaCacheKey());

        $meta = $this->generateMeta();

        //$this->writeMeta($meta = $this->generateMeta());

        return Arr::get($meta, $key);
    }

leganz avatar Oct 25 '22 22:10 leganz

Im not sure about that - its in the file based version so it must be there for a reason. I cant recreate your issues so it would be helpful to see a sample repository so I can see what you are seeing.

ryanmitchell avatar Oct 26 '22 05:10 ryanmitchell

I am going to prepare one :)

leganz avatar Oct 28 '22 07:10 leganz

@leganz any update on this?

ryanmitchell avatar Nov 14 '22 09:11 ryanmitchell

@leganz I've updated this and refactored a bit so it now works with the latest versions of Statamic and this driver. Do you want to review it before I merge it in?

ryanmitchell avatar Jun 29 '23 07:06 ryanmitchell