-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
POC - Make migration resumable #31
base: master
Are you sure you want to change the base?
POC - Make migration resumable #31
Conversation
@@ -0,0 +1,104 @@ | |||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignore this file.
private mysqli $connection; | ||
private \mysqli_stmt|false $statement; | ||
|
||
public function __construct(mysqli $connection, string $query, $offset = 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this takes a query with an offset and returns a generator that can be iterated as an array.
we can improve it to detect if there are no rows and return a null in order to support your original behavior of not truncating if there's nothing to migrate
* Connects to a mybb forum and extract different elements | ||
* Tested with MyBB v1.8.24 | ||
*/ | ||
class MyBBExtractor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the idea behind this is to isolate the queries to mybb in order to be able to change them if you want to support other forums in the future. (other mybb versions really)
try { | ||
$migrator = new Migrator( | ||
new Logger($this->output), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logger here is used to log to the console, but we can easily add a new one to log things when we are running from the web (to flarum logs? to something we can consume from the UI? )
$host, | ||
$user, | ||
$password, | ||
$db, | ||
$prefix, | ||
$path | ||
$path, | ||
$offsets |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an array that contains the counts from last run
); | ||
|
||
$migrator->setCountsDir($this->assetsDir, $this::$countsFilepath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm passing this to the Migrator to be able to save the counts. this ends up in the assets dir, so I'm not sure it's the best way, maybe we can use another part of flarum's storage?
$this->count["groups"]++; | ||
} | ||
$this->count["groups"]++; | ||
$this->saveCounts(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're saving the counts each time we migrate a thing. not sure if it's the best way, but it allows us to restart it in case an error occurs
Proof of concept for #22