Skip to content

Commit

Permalink
Merge branch 'pu/pm/TbFlyLocalNeverEmptyFlag' into '2024.11'
Browse files Browse the repository at this point in the history
tweak(TB FlySystem) local fly support never empty flag

See merge request tine20/tine20!4836
  • Loading branch information
paulmhh committed Jan 26, 2024
2 parents ee7b074 + 3c30a6c commit 1d044a7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tine20/Tinebase/Model/Tree/FlySystem/AdapterConfig/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Tinebase_Model_Tree_FlySystem_AdapterConfig_Local extends Tinebase_Record_
public const MODEL_NAME_PART = 'Tree_FlySystem_AdapterConfig_Local';

public const FLD_BASE_PATH = 'base_path';
public const FLD_NEVER_EMPTY = 'never_empty';

/**
* Holds the model configuration (must be assigned in the concrete class)
Expand All @@ -31,6 +32,9 @@ class Tinebase_Model_Tree_FlySystem_AdapterConfig_Local extends Tinebase_Record_
Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_REQUIRED,
],
],
self::FLD_NEVER_EMPTY => [
self::TYPE => self::TYPE_BOOLEAN,
],
],
];

Expand All @@ -43,6 +47,19 @@ class Tinebase_Model_Tree_FlySystem_AdapterConfig_Local extends Tinebase_Record_

public function getFlySystemAdapter(): \League\Flysystem\FilesystemAdapter
{
return new \League\Flysystem\Local\LocalFilesystemAdapter($this->{self::FLD_BASE_PATH});
$adapter = new \League\Flysystem\Local\LocalFilesystemAdapter($this->{self::FLD_BASE_PATH});
if ($this->{self::FLD_NEVER_EMPTY}) {
$success = false;
if ($adapter->directoryExists('/')) {
foreach ($adapter->listContents('/', false) as $smth) {
$success = true;
break;
}
}
if (!$success) {
throw new Tinebase_Exception_Backend('flysystem must not be empty, but it is');
}
}
return $adapter;
}
}

0 comments on commit 1d044a7

Please sign in to comment.