-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8b95b4
commit 3cb4190
Showing
6 changed files
with
128 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
/** | ||
* @link https://craftcms.com/ | ||
* @copyright Copyright (c) Pixel & Tonic, Inc. | ||
* @license MIT | ||
*/ | ||
|
||
namespace craft\awss3\migrations; | ||
|
||
use Craft; | ||
use craft\awss3\Volume; | ||
use craft\db\Migration; | ||
use craft\db\Query; | ||
use craft\helpers\Json; | ||
use craft\services\Volumes; | ||
|
||
/** | ||
* Installation Migration | ||
* | ||
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com> | ||
* @since 1.2 | ||
*/ | ||
class m190131_214300_cleanup_config extends Migration | ||
{ | ||
// Public Methods | ||
// ========================================================================= | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeUp() | ||
{ | ||
// Cleanup failed conversions | ||
$this->_convertVolumes(); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeDown() | ||
{ | ||
return true; | ||
} | ||
|
||
// Private Methods | ||
// ========================================================================= | ||
|
||
/** | ||
* Converts any old school S3 volumes to this one | ||
* | ||
* @return void | ||
*/ | ||
private function _convertVolumes() | ||
{ | ||
$projectConfig = Craft::$app->getProjectConfig(); | ||
$projectConfig->muteEvents = true; | ||
|
||
foreach ($projectConfig->get(Volumes::CONFIG_VOLUME_KEY) as $uid => &$volume) { | ||
if ($volume['type'] == Volume::class && !empty($volume['settings']) && is_array($volume['settings']) && array_key_exists('urlPrefix ', $volume['settings'])) { | ||
$settings = $volume['settings']; | ||
|
||
$hasUrls = !empty($volume['hasUrls']); | ||
$url = ($hasUrls && !empty($settings['urlPrefix'])) ? $settings['urlPrefix'] : null; | ||
$settings['region'] = $settings['location']; | ||
unset($settings['urlPrefix'], $settings['location'], $settings['storageClass']); | ||
|
||
$volume['url'] = $url; | ||
$volume['settings'] = $settings; | ||
|
||
$this->update('{{%volumes}}', [ | ||
'settings' => Json::encode($settings), | ||
'url' => $url, | ||
], ['uid' => $uid]); | ||
|
||
$projectConfig->set(Volumes::CONFIG_VOLUME_KEY . '.' . $uid, $volume); | ||
} | ||
} | ||
|
||
$projectConfig->muteEvents = false; | ||
} | ||
} |