This repository was archived by the owner on Oct 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp2phpboost.php
112 lines (89 loc) · 2.97 KB
/
wp2phpboost.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
function imp_error($errno, $errstr, $errfile, $errline, $errcontext) {
throw new Exception($errfile . '(' . $errline . ') : ' . $errstr, $errno);
}
set_error_handler('imp_error', E_ALL);
require_once __DIR__ . '/lib/IOManager.php';
require_once __DIR__ . '/lib/IOCliManager.php';
require_once __DIR__ . '/lib/Importer.php';
require_once __DIR__ . '/lib/PHPBoostAccess.php';
require_once __DIR__ . '/lib/WordPressAccess.php';
$io = new IOCliManager();
function checkPhpVersion() {
if(phpversion() < '5.4') {
throw new Exception('WP2PhpBoost require php 5.4 or never');
}
}
/**
* Get the wordpress instance path
* @return bool
*/
function getWpPath() {
global $io;
$io->write('Chemin du l\'installation de Wordpress :');
$wpPath = $io->read('wp-path');
$wpPath = (substr($wpPath, -1) === '/') ? $wpPath : $wpPath . '/';
if(file_exists($wpPath . 'wp-config.php')) {
define('WP_PATH', $wpPath);
return true;
}
return false;
}
/**
* Get the PhpBoost Path
* @return bool
*/
function getPhpBoostPath() {
global $io;
$io->write('Chemin du l\'installation de PHPBoost :');
$pBoost = $io->read('pboost-path');
$pBoost = (substr($pBoost, -1) === '/') ? $pBoost : $pBoost . '/';
if(file_exists($pBoost . 'kernel/db/config.php')) {
define('PBOOST_PATH', $pBoost);
return true;
}
return false;
}
function getImporterList() {
static $availableImporter;
global $io;
if(is_null($availableImporter)) {
$availableImporter = Importer::getAvailableImporter();
}
$io->writeln('Liste des importers existants :');
foreach($availableImporter as $importer) {
$io->writeln(' - ' . $importer['name'] . ' (' . $importer['version'] . ') : ' . $importer['description']);
}
$io->writeln();
$io->writeln('Lister les importateurs à utiliser (séparer les par une virgule) :');
$importerListStr = $io->read('list-importer');
$importerList = explode(',', $importerListStr);
$importerList = array_map(function($str) { return trim($str); }, $importerList);
foreach($importerList as $importer) {
if(!array_key_exists($importer, $availableImporter)) {
return false;
}
}
define('IMPORTER_LIST', implode(',', $importerList));
return true;
}
try {
checkPhpVersion();
if (file_exists(__DIR__ . '/config.php')) require_once __DIR__ . '/config.php';
while (!defined('WP_PATH')) getWpPath();
while (!defined('PBOOST_PATH')) getPhpBoostPath();
while (!defined('IMPORTER_LIST')) getImporterList();
// Récupération de la configuration par défaut
$defaultConfig = require_once __DIR__ . '/config-default.php';
foreach ($defaultConfig as $key => $value) {
if (!defined($key)) {
define($key, $value);
}
}
Importer::run($io, WP_PATH, PBOOST_PATH, explode(',', IMPORTER_LIST));
return true;
} catch(Exception $e) {
$io->writeln($e->getMessage());
return false;
}
?>