eloquent-driver
eloquent-driver copied to clipboard
Delete old meta after move/rename
Fixes: #70
Will this also cover the issue for renaming assets?
Should do.
As mentioned in #80 - the writeMeta data will be called 3 times. only at the first time it has the metadata
@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
Hmm that feels like an unnecessary db query - keen to avoid that. Does this change help?
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. :/
@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);
}
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.
I am going to prepare one :)
@leganz any update on this?
@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?