|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Modules; |
|
4
|
|
|
|
|
5
|
|
|
use DirectoryIterator; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Controllers\AdminController; |
|
7
|
|
|
use GeminiLabs\SiteReviews\Database\CountsManager; |
|
8
|
|
|
use GeminiLabs\SiteReviews\Database\OptionManager; |
|
9
|
|
|
use GeminiLabs\SiteReviews\Helper; |
|
10
|
|
|
use ReflectionClass; |
|
11
|
|
|
use ReflectionMethod; |
|
12
|
|
|
|
|
13
|
|
|
class Upgrader |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @return void |
|
17
|
|
|
*/ |
|
18
|
7 |
|
public function run() |
|
19
|
|
|
{ |
|
20
|
7 |
|
$filenames = []; |
|
21
|
7 |
|
$iterator = new DirectoryIterator( dirname( __FILE__ ).'/Upgrader' ); |
|
22
|
7 |
|
foreach( $iterator as $fileinfo ) { |
|
23
|
7 |
|
if( !$fileinfo->isFile() )continue; |
|
24
|
7 |
|
$filenames[] = $fileinfo->getFilename(); |
|
25
|
|
|
} |
|
26
|
7 |
|
natsort( $filenames ); |
|
27
|
7 |
|
array_walk( $filenames, function( $file ) { |
|
28
|
7 |
|
$className = str_replace( '.php', '', $file ); |
|
29
|
7 |
|
$version = str_replace( ['Upgrade_', '_'], ['', '.'], $className ); |
|
30
|
7 |
|
$versionSuffix = preg_replace( '/[\d.]+(.+)?/', '${1}', glsr()->version ); // allow alpha/beta versions |
|
31
|
7 |
|
if( version_compare( $this->currentVersion(), $version.$versionSuffix, '>=' ))return; |
|
32
|
6 |
|
glsr( 'Modules\\Upgrader\\'.$className ); |
|
33
|
6 |
|
glsr_log()->info( 'Completed Upgrade for v'.$version.$versionSuffix ); |
|
34
|
7 |
|
}); |
|
35
|
7 |
|
$this->updateVersion(); |
|
36
|
7 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return string |
|
40
|
|
|
*/ |
|
41
|
7 |
|
public function currentVersion() |
|
42
|
|
|
{ |
|
43
|
7 |
|
return glsr( OptionManager::class )->get( 'version', '0.0.0' ); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return void |
|
48
|
|
|
*/ |
|
49
|
7 |
|
public function updateVersion() |
|
50
|
|
|
{ |
|
51
|
7 |
|
$currentVersion = $this->currentVersion(); |
|
52
|
7 |
|
if( $currentVersion !== glsr()->version ) { |
|
53
|
6 |
|
glsr( OptionManager::class )->set( 'version', glsr()->version ); |
|
54
|
6 |
|
glsr( OptionManager::class )->set( 'version_upgraded_from', $currentVersion ); |
|
55
|
|
|
} |
|
56
|
7 |
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|