Skip to content
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

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Javier-Rotelli
Copy link

@Javier-Rotelli Javier-Rotelli commented Jul 6, 2022

Proof of concept for #22

@@ -0,0 +1,104 @@
<?php
Copy link
Author

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)
Copy link
Author

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
Copy link
Author

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),
Copy link
Author

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
Copy link
Author

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);
Copy link
Author

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();
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant