xref: /plugin/upgrade/legacy.php (revision 8dab6045215dcba6d736537f8a021932d3980362)
1fc9fd1daSAndreas Gohr<?php
2*8dab6045SAndreas Gohr
3fc9fd1daSAndreas Gohr/**
4fc9fd1daSAndreas Gohr * Legacy command line upgrade script
5fc9fd1daSAndreas Gohr *
6fc9fd1daSAndreas Gohr * This script can be used to upgrade old versions of DokuWiki that won't easily run on
7fc9fd1daSAndreas Gohr * modern PHP releases. It works by not actually loading any of the existing (and outdated)
8fc9fd1daSAndreas Gohr * DokuWiki code, but instead fakes an absolute minimal environment to run the upgrade.
9fc9fd1daSAndreas Gohr *
10fc9fd1daSAndreas Gohr * This means this script will make more assumptions and take shortcuts:
11fc9fd1daSAndreas Gohr *
12fc9fd1daSAndreas Gohr * - no proxy support
13fc9fd1daSAndreas Gohr * - no tmp dir changes
14fc9fd1daSAndreas Gohr * - english only
15fc9fd1daSAndreas Gohr * - only "normal" releases (no snapshots or git checkouts)
16fc9fd1daSAndreas Gohr *
17fc9fd1daSAndreas Gohr * Only use this if you can't run the normal upgrade script.
18fc9fd1daSAndreas Gohr */
19fc9fd1daSAndreas Gohr
20*8dab6045SAndreas Gohr// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
21fc9fd1daSAndreas Gohr
22fc9fd1daSAndreas Gohrrequire_once __DIR__ . '/vendor/autoload.php';
23fc9fd1daSAndreas Gohr
24fc9fd1daSAndreas Gohr// fake a minimal dokuwiki environment
25fc9fd1daSAndreas Gohrdefine('DOKU_INC', __DIR__ . '/../../../');
26fc9fd1daSAndreas Gohrglobal $conf;
27fc9fd1daSAndreas Gohr$conf['savedir'] = __DIR__ . '/../../../data/';
28fc9fd1daSAndreas Gohr$conf['cachedir'] = $conf['savedir'] . 'cache/';
29fc9fd1daSAndreas Gohr$conf['tmpdir'] = $conf['savedir'] . 'tmp/';
30fc9fd1daSAndreas Gohr$conf['proxy'] = ['host' => '', 'port' => '', 'user' => '', 'pass' => '', 'ssl' => '', 'except' => ''];
31fc9fd1daSAndreas Gohr$conf['allowdebug'] = false;
32fc9fd1daSAndreas Gohr
33*8dab6045SAndreas Gohrfunction linesToHash($lines)
34*8dab6045SAndreas Gohr{
35fc9fd1daSAndreas Gohr    $lines = array_map('trim', $lines);
36fc9fd1daSAndreas Gohr    $lines = array_filter($lines);
37fc9fd1daSAndreas Gohr    $lines = array_map(function ($item) {
38fc9fd1daSAndreas Gohr        return array_map('trim', explode(' ', $item, 2));
39fc9fd1daSAndreas Gohr    }, $lines);
40fc9fd1daSAndreas Gohr    return array_combine(array_column($lines, 0), array_column($lines, 1));
41fc9fd1daSAndreas Gohr}
42fc9fd1daSAndreas Gohr
43fc9fd1daSAndreas Gohrfunction conf_decodeString($string)
44fc9fd1daSAndreas Gohr{
45fc9fd1daSAndreas Gohr    return $string;
46fc9fd1daSAndreas Gohr}
47fc9fd1daSAndreas Gohr
48fc9fd1daSAndreas Gohrfunction filesize_h($size)
49fc9fd1daSAndreas Gohr{
50fc9fd1daSAndreas Gohr    return $size . 'b';
51fc9fd1daSAndreas Gohr}
52fc9fd1daSAndreas Gohr
53fc9fd1daSAndreas Gohrfunction hsc($string)
54fc9fd1daSAndreas Gohr{
55fc9fd1daSAndreas Gohr    return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
56fc9fd1daSAndreas Gohr}
57fc9fd1daSAndreas Gohr
58fc9fd1daSAndreas Gohrfunction io_mkdir_p($dir)
59fc9fd1daSAndreas Gohr{
60fc9fd1daSAndreas Gohr    if (file_exists($dir)) return true;
61fc9fd1daSAndreas Gohr    return mkdir($dir, 0777, true);
62fc9fd1daSAndreas Gohr}
63fc9fd1daSAndreas Gohr
64fc9fd1daSAndreas Gohrfunction getVersionData()
65fc9fd1daSAndreas Gohr{
66fc9fd1daSAndreas Gohr    $version = array();
67fc9fd1daSAndreas Gohr    if (file_exists(DOKU_INC . 'VERSION')) {
68fc9fd1daSAndreas Gohr        //official release
69fc9fd1daSAndreas Gohr        $version['date'] = trim(file_get_contents(DOKU_INC . 'VERSION'));
70fc9fd1daSAndreas Gohr        $version['type'] = 'Release';
71fc9fd1daSAndreas Gohr    }
72fc9fd1daSAndreas Gohr    return $version;
73fc9fd1daSAndreas Gohr}
74fc9fd1daSAndreas Gohr
75fc9fd1daSAndreas Gohrfunction getVersion()
76fc9fd1daSAndreas Gohr{
77fc9fd1daSAndreas Gohr    $version = getVersionData();
78fc9fd1daSAndreas Gohr    return $version['type'] . ' ' . $version['date'];
79fc9fd1daSAndreas Gohr}
80fc9fd1daSAndreas Gohr
81fc9fd1daSAndreas Gohrclass Doku_Event
82fc9fd1daSAndreas Gohr{
83fc9fd1daSAndreas Gohr    public function __construct($name, &$data)
84fc9fd1daSAndreas Gohr    {
85fc9fd1daSAndreas Gohr    }
86fc9fd1daSAndreas Gohr
87fc9fd1daSAndreas Gohr    public function advise_before()
88fc9fd1daSAndreas Gohr    {
89fc9fd1daSAndreas Gohr        return true;
90fc9fd1daSAndreas Gohr    }
91fc9fd1daSAndreas Gohr
92fc9fd1daSAndreas Gohr    public function advise_after()
93fc9fd1daSAndreas Gohr    {
94fc9fd1daSAndreas Gohr    }
95fc9fd1daSAndreas Gohr}
96fc9fd1daSAndreas Gohr
97fc9fd1daSAndreas Gohrtrait UpgradePluginTrait
98fc9fd1daSAndreas Gohr{
99fc9fd1daSAndreas Gohr    protected $lang = null;
100fc9fd1daSAndreas Gohr
101fc9fd1daSAndreas Gohr    /**
102fc9fd1daSAndreas Gohr     * @return string
103fc9fd1daSAndreas Gohr     */
104fc9fd1daSAndreas Gohr    public function getInfo()
105fc9fd1daSAndreas Gohr    {
106fc9fd1daSAndreas Gohr        $data = file(__DIR__ . '/plugin.info.txt', FILE_IGNORE_NEW_LINES);
107fc9fd1daSAndreas Gohr        return linesToHash($data);
108fc9fd1daSAndreas Gohr    }
109fc9fd1daSAndreas Gohr
110fc9fd1daSAndreas Gohr    /**
111fc9fd1daSAndreas Gohr     * @param string $key
112fc9fd1daSAndreas Gohr     * @return string
113fc9fd1daSAndreas Gohr     */
114fc9fd1daSAndreas Gohr    public function getLang($key)
115fc9fd1daSAndreas Gohr    {
116fc9fd1daSAndreas Gohr        if ($this->lang === null) {
117fc9fd1daSAndreas Gohr            $lang = [];
118fc9fd1daSAndreas Gohr            include __DIR__ . '/lang/en/lang.php';
119fc9fd1daSAndreas Gohr            $this->lang = $lang;
120fc9fd1daSAndreas Gohr        }
121fc9fd1daSAndreas Gohr        return $this->lang[$key] ?? $key;
122fc9fd1daSAndreas Gohr    }
123fc9fd1daSAndreas Gohr}
124fc9fd1daSAndreas Gohr
125fc9fd1daSAndreas Gohrabstract class DokuWiki_CLI_Plugin extends splitbrain\phpcli\CLI
126fc9fd1daSAndreas Gohr{
127fc9fd1daSAndreas Gohr    use UpgradePluginTrait;
128fc9fd1daSAndreas Gohr}
129fc9fd1daSAndreas Gohr
130fc9fd1daSAndreas Gohrclass DokuWiki_Plugin
131fc9fd1daSAndreas Gohr{
132fc9fd1daSAndreas Gohr    use UpgradePluginTrait;
133fc9fd1daSAndreas Gohr}
134fc9fd1daSAndreas Gohr
135fc9fd1daSAndreas Gohr// now the CLI plugin should load and run
136fc9fd1daSAndreas Gohrinclude(__DIR__ . '/cli.php');
137fc9fd1daSAndreas Gohr(new cli_plugin_upgrade())->run();
138