You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FileName.php 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2018 Daniel Kesselberg <mail@danielkesselberg.de>
  5. *
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  8. * @author szaimen <szaimen@e.mail.de>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\WorkflowEngine\Check;
  27. use OC\Files\Storage\Local;
  28. use OCA\WorkflowEngine\Entity\File;
  29. use OCP\Files\Mount\IMountManager;
  30. use OCP\IL10N;
  31. use OCP\IRequest;
  32. use OCP\WorkflowEngine\IFileCheck;
  33. class FileName extends AbstractStringCheck implements IFileCheck {
  34. use TFileCheck;
  35. /** @var IRequest */
  36. protected $request;
  37. /** @var IMountManager */
  38. private $mountManager;
  39. /**
  40. * @param IL10N $l
  41. * @param IRequest $request
  42. */
  43. public function __construct(IL10N $l, IRequest $request, IMountManager $mountManager) {
  44. parent::__construct($l);
  45. $this->request = $request;
  46. $this->mountManager = $mountManager;
  47. }
  48. /**
  49. * @return string
  50. */
  51. protected function getActualValue(): string {
  52. $fileName = $this->path === null ? '' : basename($this->path);
  53. if ($fileName === '' && (!$this->storage->isLocal() || $this->storage->instanceOfStorage(Local::class))) {
  54. // Return the mountpoint name of external storage that are not mounted as user home
  55. $mountPoints = $this->mountManager->findByStorageId($this->storage->getId());
  56. if (empty($mountPoints) || $mountPoints[0]->getMountType() !== 'external') {
  57. return $fileName;
  58. }
  59. $mountPointPath = rtrim($mountPoints[0]->getMountPoint(), '/');
  60. $mountPointPieces = explode('/', $mountPointPath);
  61. $mountPointName = array_pop($mountPointPieces);
  62. if (!empty($mountPointName) && $mountPointName !== 'files' && count($mountPointPieces) !== 2) {
  63. return $mountPointName;
  64. }
  65. }
  66. return $fileName;
  67. }
  68. /**
  69. * @param string $operator
  70. * @param string $checkValue
  71. * @param string $actualValue
  72. * @return bool
  73. */
  74. protected function executeStringCheck($operator, $checkValue, $actualValue): bool {
  75. if ($operator === 'is' || $operator === '!is') {
  76. $checkValue = mb_strtolower($checkValue);
  77. $actualValue = mb_strtolower($actualValue);
  78. }
  79. return parent::executeStringCheck($operator, $checkValue, $actualValue);
  80. }
  81. public function supportedEntities(): array {
  82. return [ File::class ];
  83. }
  84. public function isAvailableForScope(int $scope): bool {
  85. return true;
  86. }
  87. }