-
Notifications
You must be signed in to change notification settings - Fork 18
Use storage in ads uploads #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,8 @@ phpbb_ads_visual_demo: | |
defaults: { _controller: phpbb.ads.visual_demo.controller:handle } | ||
requirements: | ||
action: enable|disable | ||
|
||
phpbb_ads_storage_banner: | ||
path: /ads_download/{file} | ||
defaults: | ||
_controller: phpbb.ads.controller.banner:handle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll probably want to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, this can be done in the future, there is not even a pull request for this and can change in the future |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
/** | ||
* | ||
* Advertisement management. An extension for the phpBB Forum Software package. | ||
* | ||
* @copyright (c) 2017 phpBB Limited <https://www.phpbb.com> | ||
* @license GNU General Public License, version 2 (GPL-2.0) | ||
* | ||
*/ | ||
|
||
namespace phpbb\ads\migrations\v30x; | ||
|
||
use phpbb\filesystem\filesystem; | ||
use phpbb\storage\provider\local; | ||
|
||
class m1_storage extends \phpbb\db\migration\container_aware_migration | ||
{ | ||
private const BATCH_SIZE = 100; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function effectively_installed() | ||
{ | ||
/** @var filesystem $filesystem_interface */ | ||
$filesystem = $this->container->get('filesystem'); | ||
|
||
return $this->config->offsetExists('storage\\phpbb_ads\\provider') && | ||
$this->config->offsetExists('storage\\phpbb_ads\\config\\path') && | ||
$filesystem->exists($this->phpbb_root_path . 'images/phpbb_ads'); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function depends_on() | ||
{ | ||
return [ | ||
'\phpbb\db\migration\data\v400\dev', | ||
'\phpbb\ads\migrations\v20x\m1_hide_ad_for_group', | ||
]; | ||
} | ||
|
||
public function update_data() | ||
{ | ||
return [ | ||
['config.add', ['storage\\phpbb_ads\\provider', local::class]], | ||
['config.add', ['storage\\phpbb_ads\\config\\path', 'images/phpbb_ads']], | ||
['custom', [[$this, 'migrate_ads_storage']]], | ||
]; | ||
} | ||
|
||
public function migrate_ads_storage() | ||
{ | ||
/** @var filesystem $filesystem_interface */ | ||
$filesystem = $this->container->get('filesystem'); | ||
|
||
/** @var file_tracker $file_tracker */ | ||
$file_tracker = $this->container->get('storage.file_tracker'); | ||
|
||
$dir = $this->phpbb_root_path . 'images/phpbb_ads'; | ||
|
||
if (!$filesystem->exists($dir)) | ||
{ | ||
$filesystem->mkdir($dir); | ||
} | ||
|
||
$handle = @opendir($dir); | ||
|
||
if ($handle) | ||
{ | ||
$files = []; | ||
while (($file = readdir($handle)) !== false) | ||
{ | ||
if ($file === '.' || $file === '..') | ||
{ | ||
continue; | ||
} | ||
|
||
$files[] = [ | ||
'file_path' => $file, | ||
'filesize' => filesize($dir . '/' . $file), | ||
]; | ||
|
||
if (count($files) >= self::BATCH_SIZE) | ||
{ | ||
$file_tracker->track_files('phpbb_ads', $files); | ||
$files = []; | ||
} | ||
} | ||
|
||
if (!empty($files)) | ||
{ | ||
$file_tracker->track_files('phpbb_ads', $files); | ||
} | ||
|
||
closedir($handle); | ||
} | ||
} | ||
|
||
public function revert_data() | ||
{ | ||
return [ | ||
['config.remove', ['storage\\phpbb_ads\\provider']], | ||
['config.remove', ['storage\\phpbb_ads\\config\\path']], | ||
['custom', [[$this, 'revert_ads_storage']]], | ||
]; | ||
} | ||
|
||
public function revert_ads_storage() | ||
{ | ||
$this->sql_query('DELETE FROM ' . $this->tables['storage'] . ' WHERE storage = "phpbb_ads"'); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.