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

Callback during migration #67

Open
clphillips opened this issue Nov 23, 2014 · 4 comments
Open

Callback during migration #67

clphillips opened this issue Nov 23, 2014 · 4 comments

Comments

@clphillips
Copy link
Contributor

I'm thinking of adding callback support to the migration process. This would be especially useful in the API migration.

Why?
There's no feedback during migration processing. This can leave users feeling as if the app has stalled when processing a significant number of migrations.

A callback that is executed after each migration is processed would allow feedback to be presented to the user on the progress.

Thoughts?

@davedevelopment
Copy link
Owner

Doesn't it print out that it's starting a migration, and then again when it's finished? Or do you mean some sort of ticker to show something is still happening as far as we know?

@clphillips
Copy link
Contributor Author

Yes, it does print output, but that's not at all flexible. Think progress bar.

If we have a callback that is executed after each individual migration then we can completely customize the display to the user. Displaying progress bars, spinning icons, or whatever we want via CLI or GUI:

$api = new Phpmig\Api($container, $output);
$total = count($api->getMigrations($api->getVersion()));
$count = 0;

$callback = function($version) use (&$count, $total) {
    // Elaborate progress bar handler code here
    $count++;
}

$api->up($this->getVersion(), $callback);

Edit
This would actually be a better interface, since up() is well aware of the current count and total number of migrations.

$callback = function($version, $total, $count) {
    // Elaborate progress bar handler code here
}

@davedevelopment
Copy link
Owner

I see what you mean. My preference would be for the observer, pub sub or mediator pattern.

@clphillips
Copy link
Contributor Author

Right, observer would be much more flexible. How do you foresee attaching the observer? I think it's necessary to attach it to Phpmig\Api, given that it's really the only piece that is aware of the total number of migrations to process (although #66 is set to change that). Maybe #66 blocks this?

Some ideas:

$api = new Phpmig\Api($container, $output);
$progress_observer = new ObjectThatImplementsSplObserver();

$api->attachObserver($progress_observer);
$api->up($this->getVersion());

Or attach via container? I personally don't like the idea of passing a global container into a constructor, but that's a different discussion altogether.

$container['phpmig.observers'] = new \ArrayObject(new ObjectThatImplementsSplObserver());
$api = new Phpmig\Api($container, $output);

$api->up($this->getVersion());

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

No branches or pull requests

2 participants