diff options
| author | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2015-10-14 08:40:01 +0200 |
|---|---|---|
| committer | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2015-10-14 08:40:01 +0200 |
| commit | cac090b659a90749a8ea6ed7f62af980ffe7c60d (patch) | |
| tree | 154e581503145a6a7b9223850d05bb85626defe7 /phpBB/phpbb/attachment/manager.php | |
| parent | 359ef56e3538cb91f11587f77ecfc4bc423ebd96 (diff) | |
| parent | bb2634b5e5bdee53118eff8cdba3fea73932ff47 (diff) | |
| download | forums-cac090b659a90749a8ea6ed7f62af980ffe7c60d.tar forums-cac090b659a90749a8ea6ed7f62af980ffe7c60d.tar.gz forums-cac090b659a90749a8ea6ed7f62af980ffe7c60d.tar.bz2 forums-cac090b659a90749a8ea6ed7f62af980ffe7c60d.tar.xz forums-cac090b659a90749a8ea6ed7f62af980ffe7c60d.zip | |
Merge pull request #3913 from marc1706/ticket/14168
[ticket/14168] Refactor attachment management functions into classes
* marc1706/ticket/14168: (36 commits)
[ticket/14168] Correctly state return type of upload and upload_attachment
[ticket/14168] Use attachment manager instead of separate classes
[ticket/14168] Fix docblock in manager
[ticket/14168] Add more test cases for attachment manager
[ticket/14168] Add new test method and more tests
[ticket/14168] Fix tabs in manager and add test file
[ticket/14168] Fix tests after rebase
[ticket/14168] Add attachment manager service
[ticket/14168] Use correct docblock
[ticket/14168] Add services_attachment.yml to services.yml
[ticket/14168] Minor coding style fixes
[ticket/14168] Move attachment service definitions to services_attachment
[ticket/14168] Improve code coverage in upload class
[ticket/14168] Move image check and don't use trigger_error()
[ticket/14168] Add tests for init_error() during upload
[ticket/14168] Add basic test file for attachments upload
[ticket/14168] Fix CS issue
[ticket/14168] No longer use deprecated functions in core files
[ticket/14168] Move phpbb_unlink() into attachment delete class
[ticket/14168] Reset sequence before tests in delete tests
...
Diffstat (limited to 'phpBB/phpbb/attachment/manager.php')
| -rw-r--r-- | phpBB/phpbb/attachment/manager.php | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/phpBB/phpbb/attachment/manager.php b/phpBB/phpbb/attachment/manager.php new file mode 100644 index 0000000000..3c47171b2f --- /dev/null +++ b/phpBB/phpbb/attachment/manager.php @@ -0,0 +1,99 @@ +<?php +/** + * + * This file is part of the phpBB Forum Software package. + * + * @copyright (c) phpBB Limited <https://www.phpbb.com> + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\attachment; + +/** + * Attachment manager + */ +class manager +{ + /** @var delete Attachment delete class */ + protected $delete; + + /** @var resync Attachment resync class */ + protected $resync; + + /** @var upload Attachment upload class */ + protected $upload; + + /** + * Constructor for attachment manager + * + * @param delete $delete Attachment delete class + * @param resync $resync Attachment resync class + * @param upload $upload Attachment upload class + */ + public function __construct(delete $delete, resync $resync, upload $upload) + { + $this->delete = $delete; + $this->resync = $resync; + $this->upload = $upload; + } + + /** + * Wrapper method for deleting attachments + * + * @param string $mode can be: post|message|topic|attach|user + * @param mixed $ids can be: post_ids, message_ids, topic_ids, attach_ids, user_ids + * @param bool $resync set this to false if you are deleting posts or topics + * + * @return int|bool Number of deleted attachments or false if something + * went wrong during attachment deletion + */ + public function delete($mode, $ids, $resync = true) + { + return $this->delete->delete($mode, $ids, $resync); + } + + /** + * Wrapper method for deleting attachments from filesystem + * + * @param string $filename Filename of attachment + * @param string $mode Delete mode + * @param bool $entry_removed Whether entry was removed. Defaults to false + * @return bool True if file was removed, false if not + */ + public function unlink($filename, $mode = 'file', $entry_removed = false) + { + return $this->delete->unlink_attachment($filename, $mode, $entry_removed); + } + + /** + * Wrapper method for resyncing specified type + * + * @param string $type Type of resync + * @param array $ids IDs to resync + */ + public function resync($type, $ids) + { + $this->resync->resync($type, $ids); + } + + /** + * Wrapper method for uploading attachment + * + * @param string $form_name The form name of the file upload input + * @param int $forum_id The id of the forum + * @param bool $local Whether the file is local or not + * @param string $local_storage The path to the local file + * @param bool $is_message Whether it is a PM or not + * @param array $local_filedata An file data object created for the local file + * + * @return array File data array + */ + public function upload($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = []) + { + return $this->upload->upload($form_name, $forum_id, $local, $local_storage, $is_message, $local_filedata); + } +} |
