Skip to content

Commit

Permalink
Fixed #47
Browse files Browse the repository at this point in the history
  • Loading branch information
andris-sevcenko committed Mar 5, 2019
1 parent a84693e commit a34e6f5
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes for Amazon S3 for Craft CMS

## Unreleased

### Fixed
- Fixed an error that occurred if expiry time was set up incorrectly. ([#47](https://github.com/craftcms/aws-s3/issues/47))

## 1.2.0 - 2019-02-21

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Plugin extends \craft\base\Plugin
/**
* @inheritdoc
*/
public $schemaVersion = '1.1';
public $schemaVersion = '1.2';


// Public Methods
Expand Down
69 changes: 69 additions & 0 deletions src/migrations/m190305_133000_cleanup_expires_config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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\helpers\Json;
use craft\services\Volumes;

/**
* Installation Migration
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 1.2
*/
class m190305_133000_cleanup_expires_config extends Migration
{
// Public Methods
// =========================================================================

/**
* @inheritdoc
*/
public function safeUp()
{
// Cleanup failed conversions
$projectConfig = Craft::$app->getProjectConfig();

$schemaVersion = $projectConfig->get('plugins.aws-s3.schemaVersion', true);
$projectConfig->muteEvents = true;

$volumes = $projectConfig->get(Volumes::CONFIG_VOLUME_KEY, true) ?? [];

foreach ($volumes as $uid => &$volume) {
if ($volume['type'] === Volume::class && !empty($volume['settings']) && is_array($volume['settings']) && array_key_exists('expires', $volume['settings'])) {
if (preg_match('/^([\d]+)([a-z]+)$/', $volume['settings']['expires'], $matches)) {
$volume['settings']['expires'] = $matches[1] . ' ' . $matches[2];

$this->update('{{%volumes}}', [
'settings' => Json::encode($volume['settings'])
], ['uid' => $uid]);

// If project config schema up to date, don't update project config
if (!version_compare($schemaVersion, '1.2', '>=')) {
$projectConfig->set(Volumes::CONFIG_VOLUME_KEY . '.' . $uid, $volume);
}
}
}
}

$projectConfig->muteEvents = false;

return true;
}

/**
* @inheritdoc
*/
public function safeDown()
{
return true;
}
}

0 comments on commit a34e6f5

Please sign in to comment.