Skip to content

Commit

Permalink
Merge branch 'feature/craft31' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hibberd committed Jan 18, 2019
2 parents 9d23010 + 6222bf8 commit 32ccde9
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 54 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Linkit Changelog
> One link field to rule them all, built for [Craft 3](http://craftcms.com)
## 1.1.6 - 2019-01-17

### Fixed

* Fixed Craft 2 migration error preventing install on Craft 3.1.x
* Removed some unused template tags
* Fixed issues bug on the about page

## 1.1.5.1 - 2019-01-15

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "fruitstudios/linkit",
"description": "One link field to rule them all.",
"type": "craft-plugin",
"version": "1.1.5.1",
"version": "1.1.6",
"keywords": [
"craft",
"cms",
Expand Down
2 changes: 1 addition & 1 deletion src/Linkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Linkit extends Plugin
// Public Methods
// =========================================================================

public $schemaVersion = '1.0.7.1';
public $schemaVersion = '1.0.8';

public function init()
{
Expand Down
54 changes: 31 additions & 23 deletions src/migrations/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Craft;
use craft\db\Migration;
use craft\helpers\Json;
use craft\services\Fields;
use craft\services\Plugins;

class Install extends Migration
{
Expand All @@ -26,37 +28,43 @@ public function safeUp()

private function _upgradeFromCraft2()
{
// Locate and remove old linkit
$row = (new \craft\db\Query())
->select(['id', 'settings'])
->from(['{{%plugins}}'])
->where(['in', 'handle', ['fruitlinkit', 'fruit-link-it', 'fruit-linkit']])
->one();
// Get Project Config
$projectConfig = Craft::$app->getProjectConfig();

if($row)
// Don't make the same config changes twice
$schemaVersion = $projectConfig->get('plugins.linkit.schemaVersion', true);
if (version_compare($schemaVersion, '3.1.8', '>='))
{
$this->delete('{{%plugins}}', ['id' => $row['id']]);
return;
}

// Look for any old linkit fields and update their settings
$fields = (new \craft\db\Query())
->select(['id', 'settings'])
->from(['{{%fields}}'])
->where(['in', 'type', ['FruitLinkIt']])
->all();
// Locate and remove old linkit
$plugins = $projectConfig->get(Plugins::CONFIG_PLUGINS_KEY) ?? [];
foreach ($plugins as $pluginHandle => $pluginData)
{
switch ($pluginHandle)
{
case 'fruitlinkit':
case 'fruit-link-it':
case 'fruit-linkit':
$projectConfig->remove(Plugins::CONFIG_PLUGINS_KEY . '.' . $pluginHandle);
break;
}
}

if($fields)

// Get the field data from the project config
$fields = $projectConfig->get(Fields::CONFIG_FIELDS_KEY) ?? [];
foreach ($fields as $fieldUid => $fieldData)
{
// Update field settings
foreach($fields as $field)
if ($fieldData['type'] === 'FruitLinkIt')
{
$oldSettings = $field['settings'] ? Json::decode($field['settings']) : null;
$newSettings = $this->_migrateFieldSettings($oldSettings);
$oldSettings = $fieldData['settings'] ? Json::decode($fieldData['settings']) : null;

$fieldData['type'] = LinkitField::class;
$fieldData['settings'] = $this->_migrateFieldSettings($oldSettings);

$this->update('{{%fields}}', [
'type' => LinkitField::class,
'settings' => Json::encode($newSettings)
], ['id' => $field['id']]);
$projectConfig->set(Fields::CONFIG_FIELDS_KEY . '.' . $fieldUid, $fieldData);
}
}

Expand Down
53 changes: 30 additions & 23 deletions src/migrations/m180423_175007_linkit_craft2.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Craft;
use craft\db\Migration;
use craft\helpers\Json;
use craft\services\Fields;
use craft\services\Plugins;

class m180423_175007_linkit_craft2 extends Migration
{
Expand All @@ -27,37 +29,42 @@ public function safeUp()

private function _upgradeFromCraft2()
{
// Locate and remove old linkit
$row = (new \craft\db\Query())
->select(['id', 'settings'])
->from(['{{%plugins}}'])
->where(['in', 'handle', ['fruitlinkit', 'fruit-link-it', 'fruit-linkit']])
->one();
// Get Project Config
$projectConfig = Craft::$app->getProjectConfig();

if($row)
// Don't make the same config changes twice
$schemaVersion = $projectConfig->get('plugins.linkit.schemaVersion', true);
if (version_compare($schemaVersion, '3.1.8', '>='))
{
$this->delete('{{%plugins}}', ['id' => $row['id']]);
return;
}

// Look for any old linkit fields and update their settings
$fields = (new \craft\db\Query())
->select(['id', 'settings'])
->from(['{{%fields}}'])
->where(['in', 'type', ['FruitLinkIt']])
->all();
// Locate and remove old linkit
$plugins = $projectConfig->get(Plugins::CONFIG_PLUGINS_KEY) ?? [];
foreach ($plugins as $pluginHandle => $pluginData)
{
switch ($pluginHandle)
{
case 'fruitlinkit':
case 'fruit-link-it':
case 'fruit-linkit':
$projectConfig->remove(Plugins::CONFIG_PLUGINS_KEY . '.' . $pluginHandle);
break;
}
}

if($fields)
// Get the field data from the project config
$fields = $projectConfig->get(Fields::CONFIG_FIELDS_KEY) ?? [];
foreach ($fields as $fieldUid => $fieldData)
{
// Update field settings
foreach($fields as $field)
if ($fieldData['type'] === 'FruitLinkIt')
{
$oldSettings = $field['settings'] ? Json::decode($field['settings']) : null;
$newSettings = $this->_migrateFieldSettings($oldSettings);
$oldSettings = $fieldData['settings'] ? Json::decode($fieldData['settings']) : null;

$fieldData['type'] = LinkitField::class;
$fieldData['settings'] = $this->_migrateFieldSettings($oldSettings);

$this->update('{{%fields}}', [
'type' => LinkitField::class,
'settings' => Json::encode($newSettings)
], ['id' => $field['id']]);
$projectConfig->set(Fields::CONFIG_FIELDS_KEY . '.' . $fieldUid, $fieldData);
}
}

Expand Down
14 changes: 8 additions & 6 deletions src/templates/fields/_settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
}) }}
#}

{{ forms.lightSwitchField({
id: 'enableAllTypes',
label: 'Enable all link types',
instructions: 'Switch on all link types for this field',
on: false,
}) }}
{#
{{ forms.lightSwitchField({
id: 'enableAllTypes',
label: 'Enable all link types',
instructions: 'Switch on all link types for this field',
on: false,
}) }}
#}

{{ forms.field({
errors: field.getErrors('enabledLinkTypes'),
Expand Down

0 comments on commit 32ccde9

Please sign in to comment.