|
@@ -2,9 +2,13 @@
|
|
|
|
|
|
namespace App\Services\File;
|
|
|
|
|
|
+use App\Exceptions\ValidationException;
|
|
|
use App\Models\Enums\FileObjectType;
|
|
|
use App\Models\Enums\FileSource;
|
|
|
use App\Models\File;
|
|
|
+use App\Models\Library;
|
|
|
+use App\Models\NamingRule;
|
|
|
+use App\Services\NamingRule\NamingRuleCheck;
|
|
|
use Carbon\Carbon;
|
|
|
use Illuminate\Support\Collection;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
@@ -47,6 +51,40 @@ class FileAssociationService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public function fileNameNamingRuleCheckByContainer(int $libraryId, int $namingRuleId = 0)
|
|
|
+ {
|
|
|
+ if (! $namingRuleId) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $library = Library::query()->findOrFail($libraryId);
|
|
|
+ $namingRule = NamingRule::query()->findOrFail($namingRuleId);
|
|
|
+
|
|
|
+ $namingRuleCheck = new NamingRuleCheck();
|
|
|
+
|
|
|
+ $code = $namingRuleCheck->getNamingRuleCode($library);
|
|
|
+
|
|
|
+ $errors = [];
|
|
|
+ foreach ($this->files as $file) {
|
|
|
+ $fileName = pathinfo($file->title)['filename'];
|
|
|
+
|
|
|
+ $result = $namingRuleCheck->checkByName($fileName, $namingRule, $code);
|
|
|
+ if (! $result['result']) {
|
|
|
+ $errors[] = [
|
|
|
+ ...$result,
|
|
|
+ 'name' => $file->title,
|
|
|
+ 'file_id' => $file->id
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($errors) {
|
|
|
+ throw new ValidationException('The file name does not conform to the naming rules', errors: [
|
|
|
+ 'naming_rule' => $errors
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public function association(string $objectId,)
|
|
|
{
|
|
|
if (! $this->files) {
|