| 1 |
<?php namespace Datafeedr\Api\Migrations; |
| 2 |
|
| 3 |
/** |
| 4 |
* Class Migration |
| 5 |
* @package Datafeedr\Api\Migrations |
| 6 |
* |
| 7 |
* @since 2.0.0 |
| 8 |
* |
| 9 |
* Contains the version() method for extracting the version number from the |
| 10 |
* Migration class name. |
| 11 |
*/ |
| 12 |
abstract class Migration { |
| 13 |
|
| 14 |
/** |
| 15 |
* Returns the migration version by extracting it from the Migration class name. |
| 16 |
* |
| 17 |
* For example, if the class is named Migration_20180118151744_Create_New_Option() |
| 18 |
* |
| 19 |
* Then this function will return 20180118151744. |
| 20 |
* |
| 21 |
* If the version was not found in this class name, this function will return a very high number |
| 22 |
* which should never be considered a proper DB version number because I don't expect there will |
| 23 |
* still be WordPress websites in the year 3000. ;) |
| 24 |
* |
| 25 |
* @since 2.0.0 |
| 26 |
* |
| 27 |
* @return string |
| 28 |
*/ |
| 29 |
public function version() { |
| 30 |
$called_class = get_called_class(); |
| 31 |
$class_parts = explode( '_', $called_class ); |
| 32 |
foreach ( $class_parts as $part ) { |
| 33 |
if ( is_numeric( $part ) ) { |
| 34 |
return $part; |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Return a high version number because one was not found in the called class name. |
| 40 |
* |
| 41 |
* This will prevent the migration script from rerunning the same migration over and over |
| 42 |
* because no version was returned. |
| 43 |
*/ |
| 44 |
return '30000111111111'; |
| 45 |
} |
| 46 |
} |
| 47 |
|