/** * Handle renames */ public function onBeforeWrite() { $bucket = CloudAssets::inst()->map($this->owner->getFilename()); if ($bucket) { if (!$this->owner->isChanged('Filename')) { return; } $changedFields = $this->owner->getChangedFields(); $pathBefore = $changedFields['Filename']['before']; $pathAfter = $changedFields['Filename']['after']; // If the file or folder didn't exist before, don't rename - its created if (!$pathBefore) { return; } // Tell the remote to rename the file (or delete and recreate or whatever) if ($this->owner->hasMethod('onBeforeCloudRename')) { $this->owner->onBeforeCloudRename($pathBefore, $pathAfter); } CloudAssets::inst()->getLogger()->info("CloudAssets: Renaming {$pathBefore} to {$pathAfter}"); $bucket->rename($this->owner, $pathBefore, $pathAfter); if ($this->owner->hasMethod('onAfterCloudRename')) { $this->owner->onAfterCloudRename($pathBefore, $pathAfter); } } }
public function invalidate(File $file) { // To prevent writing to the cache from invalidating it if (!$file->isChanged('FileContentCache')) { $file->FileContentCache = ''; } }