Overview
Comment:Add signals for file store, delete, move and mkdir
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA3-256: 2c39d43b6eca77813287ebb4aa8a0b60cf57314eef2d5bb28ffe6f6c2b897864
User & Date: bohwaz on 2021-03-29 23:03:03
Other Links: branch diff | manifest | tags
Context
2021-03-29
23:33
Fix preview in skriv editor in documents check-in: 266c0e4891 user: bohwaz tags: dev
23:03
Add signals for file store, delete, move and mkdir check-in: 2c39d43b6e user: bohwaz tags: dev
22:26
Add plugin signals to entity save and delete, fix [0b24b95430b2da29] check-in: 15a175a211 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Entities/Files/File.php from [b130d94d8a] to [484cde5ea4].

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
<?php

namespace Garradin\Entities\Files;

use KD2\Graphics\Image;
use KD2\DB\EntityManager as EM;

use Garradin\DB;
use Garradin\Entity;

use Garradin\UserException;
use Garradin\ValidationException;
use Garradin\Membres\Session;
use Garradin\Static_Cache;
use Garradin\Utils;
use Garradin\Entities\Web\Page;










>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php

namespace Garradin\Entities\Files;

use KD2\Graphics\Image;
use KD2\DB\EntityManager as EM;

use Garradin\DB;
use Garradin\Entity;
use Garradin\Plugin;
use Garradin\UserException;
use Garradin\ValidationException;
use Garradin\Membres\Session;
use Garradin\Static_Cache;
use Garradin\Utils;
use Garradin\Entities\Web\Page;

162
163
164
165
166
167
168


169
170
171
172
173
174
175
	public function delete(): bool
	{
		Files::callStorage('checkLock');

		// Delete actual file content
		Files::callStorage('delete', $this);



		// clean up thumbnails
		foreach (self::ALLOWED_THUMB_SIZES as $size)
		{
			Static_Cache::remove(sprintf(self::THUMB_CACHE_ID, $this->pathHash(), $size));
		}

		if ($this->exists()) {







>
>







163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
	public function delete(): bool
	{
		Files::callStorage('checkLock');

		// Delete actual file content
		Files::callStorage('delete', $this);

		Plugin::fireSignal('files.delete', ['file' => $this]);

		// clean up thumbnails
		foreach (self::ALLOWED_THUMB_SIZES as $size)
		{
			Static_Cache::remove(sprintf(self::THUMB_CACHE_ID, $this->pathHash(), $size));
		}

		if ($this->exists()) {
188
189
190
191
192
193
194
195




196
197
198
199
200
201
202
	{
		self::validatePath($new_path);

		if ($new_path == $this->path || 0 === strpos($new_path, $this->path)) {
			throw new UserException('Impossible de renommer ou déplacer un fichier vers lui-même');
		}

		return Files::callStorage('move', $this, $new_path);




	}

	public function setContent(string $content): self
	{
		$this->set('modified', new \DateTime);
		$this->store(null, rtrim($content));
		$this->indexForSearch(null, $content);







|
>
>
>
>







191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
	{
		self::validatePath($new_path);

		if ($new_path == $this->path || 0 === strpos($new_path, $this->path)) {
			throw new UserException('Impossible de renommer ou déplacer un fichier vers lui-même');
		}

		$return = Files::callStorage('move', $this, $new_path);

		Plugin::fireSignal('files.move', ['file' => $this, 'new_path' => $new_path]);

		return $return;
	}

	public function setContent(string $content): self
	{
		$this->set('modified', new \DateTime);
		$this->store(null, rtrim($content));
		$this->indexForSearch(null, $content);
259
260
261
262
263
264
265


266
267
268
269
270
271
272
		else {
			$return = Files::callStorage('storeContent', $this, $source_content);
		}

		if (!$return) {
			throw new UserException('Le fichier n\'a pas pu être enregistré.');
		}



		if (!$index_search) {
			$this->indexForSearch($source_path, $source_content);
		}

		return $this;
	}







>
>







266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
		else {
			$return = Files::callStorage('storeContent', $this, $source_content);
		}

		if (!$return) {
			throw new UserException('Le fichier n\'a pas pu être enregistré.');
		}

		Plugin::fireSignal('files.store', ['file' => $this]);

		if (!$index_search) {
			$this->indexForSearch($source_path, $source_content);
		}

		return $this;
	}
333
334
335
336
337
338
339


340
341
342
343
344
345
346
		$file->set('name', $name);
		$file->set('parent', $path);
		$file->set('type', self::TYPE_DIRECTORY);
		$file->set('image', 0);
		$file->set('modified', new \DateTime);

		Files::callStorage('mkdir', $file);



		return $file;
	}

	static public function ensureDirectoryExists(string $path): void
	{
		$db = DB::getInstance();







>
>







342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
		$file->set('name', $name);
		$file->set('parent', $path);
		$file->set('type', self::TYPE_DIRECTORY);
		$file->set('image', 0);
		$file->set('modified', new \DateTime);

		Files::callStorage('mkdir', $file);

		Plugin::fireSignal('files.mkdir', ['file' => $file]);

		return $file;
	}

	static public function ensureDirectoryExists(string $path): void
	{
		$db = DB::getInstance();