1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* uninstall.php - cleanup on module uninstall |
4
|
|
|
* |
5
|
|
|
* @author XOOPS Module Development Team |
6
|
|
|
* @copyright {@link https://xoops.org 2001-2016 XOOPS Project} |
7
|
|
|
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
8
|
|
|
* @link https://xoops.org XOOPS |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @internal {Make sure you PROTECT THIS FILE} |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
use XoopsModules\Xsitemap\{ |
16
|
|
|
Helper, |
17
|
|
|
Utility |
18
|
|
|
}; |
19
|
|
|
/** @var Utility $utility */ |
20
|
|
|
/** @var Helper $helper */ |
21
|
|
|
|
22
|
|
|
if ((!defined('XOOPS_ROOT_PATH')) |
23
|
|
|
|| !($GLOBALS['xoopsUser'] instanceof \XoopsUser) |
24
|
|
|
|| !$GLOBALS['xoopsUser']->isAdmin()) { |
25
|
|
|
exit('Restricted access' . PHP_EOL); |
26
|
|
|
} |
27
|
|
|
/** |
28
|
|
|
* Function to perform before module uninstall |
29
|
|
|
* |
30
|
|
|
* @param \XoopsModule $module |
31
|
|
|
* |
32
|
|
|
* @return bool true if successfully executed, false if not |
33
|
|
|
*/ |
34
|
|
|
function xoops_module_pre_uninstall_xsitemap(\XoopsModule $module) |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
return true; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Function to complete upon module uninstall |
41
|
|
|
* |
42
|
|
|
* @param \XoopsModule $module |
43
|
|
|
* |
44
|
|
|
* @return bool true if successfully executed uninstall of module, false if not |
45
|
|
|
*/ |
46
|
|
|
function xoops_module_uninstall_xsitemap(\XoopsModule $module) |
47
|
|
|
{ |
48
|
|
|
// return true; |
49
|
|
|
$moduleDirName = $module->getVar('dirname'); |
50
|
|
|
$helper = Helper::getInstance(); |
51
|
|
|
$utility = new Utility(); |
52
|
|
|
$delOk = false; |
53
|
|
|
// if (!class_exists($utility)) { |
54
|
|
|
// xoops_load('utility', $moduleDirName); |
55
|
|
|
// } |
56
|
|
|
$success = true; |
57
|
|
|
$helper->loadLanguage('admin'); |
58
|
|
|
//------------------------------------------------------------------ |
59
|
|
|
// Remove xSitemap uploads folder (and all subfolders) if they exist |
60
|
|
|
//------------------------------------------------------------------ |
61
|
|
|
$old_directories = [$GLOBALS['xoops']->path("uploads/{$moduleDirName}")]; |
62
|
|
|
foreach ($old_directories as $old_dir) { |
63
|
|
|
$dirInfo = new \SplFileInfo($old_dir); |
64
|
|
|
if ($dirInfo->isDir()) { |
65
|
|
|
// The directory exists so delete it |
66
|
|
|
if (false === $utility::rrmdir($old_dir)) { |
67
|
|
|
$module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_DEL_PATH, $old_dir)); |
68
|
|
|
$success = false; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
unset($dirInfo); |
72
|
|
|
} |
73
|
|
|
//------------------------------------------------------------------ |
74
|
|
|
// Remove xsitemap.xml from XOOPS root folder if it exists |
75
|
|
|
//------------------------------------------------------------------ |
76
|
|
|
$xmlfile = $GLOBALS['xoops']->path('xsitemap.xml'); |
77
|
|
|
if (is_file($xmlfile)) { |
78
|
|
|
if (false === ($delOk = unlink($xmlfile))) { |
79
|
|
|
$module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $xmlfile)); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
return $success && $delOk; |
83
|
|
|
} |
84
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.