Skip to content

Commit 968ee36

Browse files
committed
Migration from other plugins (fixes #33)
1 parent cfc96c9 commit 968ee36

File tree

14 files changed

+495
-5
lines changed

14 files changed

+495
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Types of changes
1616

1717
## [Unreleased]
1818

19+
## 1.12.0 - 2019-06-18
20+
21+
### Added
22+
* Added functionality of migration from other plugins
23+
1924
## 1.11.1 - 2019-06-12
2025

2126
### Fixed

Plugin.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use GinoPane\BlogTaxonomy\Components\SeriesPosts;
1717
use GinoPane\BlogTaxonomy\Components\RelatedPosts;
1818
use GinoPane\BlogTaxonomy\Components\RelatedSeries;
19+
use GinoPane\BlogTaxonomy\Console\MigrateFromPlugin;
1920
use RainLab\Blog\Controllers\Posts as PostsController;
2021
use GinoPane\BlogTaxonomy\Components\SeriesNavigation;
2122
use RainLab\Blog\Controllers\Categories as CategoriesController;
@@ -45,7 +46,7 @@ class Plugin extends PluginBase
4546
*
4647
* @return array
4748
*/
48-
public function pluginDetails()
49+
public function pluginDetails(): array
4950
{
5051
return [
5152
'name' => self::LOCALIZATION_KEY . 'plugin.name',
@@ -61,7 +62,7 @@ public function pluginDetails()
6162
*
6263
* @return array
6364
*/
64-
public function registerComponents()
65+
public function registerComponents(): array
6566
{
6667
return [
6768
TagList::class => TagList::NAME,
@@ -74,6 +75,14 @@ public function registerComponents()
7475
];
7576
}
7677

78+
/**
79+
*
80+
*/
81+
public function register()
82+
{
83+
$this->registerConsoleCommand(MigrateFromPlugin::NAME, MigrateFromPlugin::class);
84+
}
85+
7786
/**
7887
* Boot method, called right before the request route
7988
*/

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Taxonomy extension for [RainLab Blog](https://octobercms.com/plugin/rainlab-blog
99
## Table of Contents
1010
* [Changes to Original Blog Plugin](#changes-to-original-blog-plugin)
1111
* [Translate Plugin Support](#translate-plugin-support)
12+
* [Migration from Other Plugins](#migration-from-other-plugins)
1213
* [Implementing Frontend Pages](#implementing-frontend-pages)
1314
* [Post Series Navigation](#post-series-navigation)
1415
* [Posts in the Series](#posts-in-the-series)
@@ -39,6 +40,46 @@ They were also placed in a new tag-like style along with tags and series in thei
3940

4041
Starting from 1.5.0 version Blog Taxonomy supports [RainLab Translate](https://octobercms.com/plugin/rainlab-translate) plugin when it's installed. All tag and series fields could be translated.
4142

43+
## Migration from Other Plugins
44+
45+
Starting from 1.12.0 version Blog Taxonomy supports migration from other plugins. Currently supported plugins are: [BlogSeries](https://github.com/PascalKleindienst/october-blogseries-extension).
46+
47+
The migration is done via console command:
48+
49+
```php artisan blogtaxonomy:migrate PKleindienst.BlogSeries```
50+
51+
Use `-h` or `--help` to get usage help.
52+
53+
Migration example output:
54+
55+
```bash
56+
**************************************************
57+
* Migration from PKleindienst.BlogSeries *
58+
**************************************************
59+
60+
Migrating series
61+
2 series found
62+
Series "Series 1" => Blog Taxonomy Series "Series 1" (#3)
63+
Series "Series 2" => Blog Taxonomy Series "Series 2" (#4)
64+
All series have been migrated
65+
66+
Migrating related series
67+
Relation "#4" => "#3" added
68+
Relation "#3" => "#4" added
69+
Related series have been migrated
70+
71+
72+
Do you want to assign newly created series to posts (already assigned Blog Taxonomy series will be overwritten) (yes/no) [no]:
73+
> yes
74+
75+
Migrating series assigned to posts
76+
Series "#3" has been assigned to a post
77+
Series "#4" has been assigned to a post
78+
Migrated series has been assigned
79+
80+
Migration from PKleindienst.BlogSeries finished
81+
```
82+
4283
## Implementing Frontend Pages
4384
4485
The Blog Taxonomy plugin provides several useful components with basic markup for frontend usage. The default markup
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace GinoPane\BlogTaxonomy\Classes\MigrationCommand;
4+
5+
use GinoPane\BlogTaxonomy\Classes\MigrationCommand\Exceptions\NoPluginException;
6+
use GinoPane\BlogTaxonomy\Classes\MigrationCommand\Migrations\NullMigration;
7+
use GinoPane\BlogTaxonomy\Classes\MigrationCommand\Migrations\PkleindienstBlogSeriesMigration;
8+
use Illuminate\Console\Command;
9+
10+
/**
11+
* Class MigrationFactory
12+
*
13+
* @package GinoPane\BlogTaxonomy\Classes\MigrationCommand
14+
*/
15+
class MigrationFactory
16+
{
17+
/**
18+
* @param string $plugin
19+
*
20+
* @throws NoPluginException
21+
*
22+
* @return MigrationInterface
23+
*/
24+
public static function resolve(string $plugin, Command $command): MigrationInterface
25+
{
26+
$plugin = strtolower($plugin);
27+
$migration = new NullMigration($command);
28+
29+
switch ($plugin) {
30+
case strtolower(PkleindienstBlogSeriesMigration::PLUGIN_NAME):
31+
$migration = new PkleindienstBlogSeriesMigration($command);
32+
}
33+
34+
return $migration;
35+
}
36+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace GinoPane\BlogTaxonomy\Classes\MigrationCommand;
4+
5+
/**
6+
* Class MigrationInterface
7+
*
8+
* @package GinoPane\BlogTaxonomy\Classes\MigrationCommand
9+
*/
10+
interface MigrationInterface
11+
{
12+
/**
13+
* @return void
14+
*/
15+
public function migrate();
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace GinoPane\BlogTaxonomy\Classes\MigrationCommand\Exceptions;
4+
5+
use Exception;
6+
7+
/**
8+
* Class NoDataException
9+
*
10+
* @package GinoPane\BlogTaxonomy\Classes\MigrationCommand\Exceptions
11+
*/
12+
class NoDataException extends Exception
13+
{
14+
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace GinoPane\BlogTaxonomy\Classes\MigrationCommand\Exceptions;
4+
5+
use Exception;
6+
7+
/**
8+
* Class NoPluginException
9+
*
10+
* @package GinoPane\BlogTaxonomy\Classes\MigrationCommand\Exceptions
11+
*/
12+
class NoPluginException extends Exception
13+
{
14+
public function __construct(string $pluginName)
15+
{
16+
parent::__construct("$pluginName plugin does not exist in the system. Please check if it is installed and try again.");
17+
}
18+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace GinoPane\BlogTaxonomy\Classes\MigrationCommand\Migrations;
4+
5+
use Illuminate\Console\Command;
6+
use System\Classes\PluginManager;
7+
use GinoPane\BlogTaxonomy\Classes\MigrationCommand\MigrationInterface;
8+
use GinoPane\BlogTaxonomy\Classes\MigrationCommand\Exceptions\NoPluginException;
9+
10+
/**
11+
* Class PkleindienstBlogSeriesMigration
12+
*
13+
* @package GinoPane\BlogTaxonomy\Classes\MigrationCommand\Migrations
14+
*/
15+
abstract class AbstractMigration implements MigrationInterface
16+
{
17+
const PLUGIN_NAME = '';
18+
19+
/**
20+
* @var Command
21+
*/
22+
protected $command;
23+
24+
/**
25+
* AbstractMigration constructor.
26+
*
27+
* @param Command $command
28+
*
29+
* @throws NoPluginException
30+
*/
31+
public function __construct(Command $command)
32+
{
33+
$this->validate();
34+
35+
$this->command = $command;
36+
}
37+
38+
/**
39+
* @return void
40+
*/
41+
public function migrate()
42+
{
43+
$this->command->alert('Migration from ' . static::PLUGIN_NAME);
44+
45+
$this->migratePlugin();
46+
47+
$this->command->info('Migration from ' . static::PLUGIN_NAME . ' finished');
48+
}
49+
50+
abstract protected function migratePlugin();
51+
52+
/**
53+
* @throws NoPluginException
54+
*/
55+
protected function validate()
56+
{
57+
$pluginManager = PluginManager::instance();
58+
59+
if (!$pluginManager->hasPlugin(static::PLUGIN_NAME)) {
60+
throw new NoPluginException(static::PLUGIN_NAME);
61+
}
62+
}
63+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace GinoPane\BlogTaxonomy\Classes\MigrationCommand\Migrations;
4+
5+
/**
6+
* Class NullMigration
7+
*
8+
* @package GinoPane\BlogTaxonomy\Classes\MigrationCommand\Migrations
9+
*/
10+
class NullMigration extends AbstractMigration
11+
{
12+
/**
13+
* @return void
14+
*/
15+
public function migrate()
16+
{
17+
$this->command->error('Found no suitable plugins for migration. Use help (-h, --help) to see available options.');
18+
}
19+
20+
/**
21+
* No validation required for this null implementation
22+
*/
23+
protected function validate()
24+
{
25+
return null;
26+
}
27+
28+
/**
29+
* @return null
30+
*/
31+
protected function migratePlugin()
32+
{
33+
return null;
34+
}
35+
}

0 commit comments

Comments
 (0)