File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
apps/files_versions/lib/Listener Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -196,8 +196,8 @@ public function post_write_hook(Node $node): void {
196196 }
197197
198198 if (
199- $ writeHookInfo ['versionCreated ' ] &&
200- $ node ->getMTime () !== $ writeHookInfo ['previousNode ' ]->getMTime ()
199+ $ writeHookInfo ['versionCreated ' ]
200+ && $ node ->getMTime () !== $ writeHookInfo ['previousNode ' ]->getMTime ()
201201 ) {
202202 // If a new version was created, insert a version in the DB for the current content.
203203 // If both versions have the same mtime, it means the latest version file simply got overrode,
@@ -218,6 +218,15 @@ public function post_write_hook(Node $node): void {
218218 ],
219219 );
220220 }
221+ } catch (DoesNotExistException $ e ) {
222+ // This happens if the versions app was not enabled while the file was created or updated the last time.
223+ // meaning there is no such revision and we need to create this file.
224+ if ($ writeHookInfo ['versionCreated ' ]) {
225+ $ this ->created ($ node );
226+ } else {
227+ // Normally this should not happen so we re-throw the exception to not hide any potential issues.
228+ throw $ e ;
229+ }
221230 } catch (Exception $ e ) {
222231 $ this ->logger ->error ('Failed to update existing version for ' . $ node ->getPath (), [
223232 'exception ' => $ e ,
You can’t perform that action at this time.
0 commit comments