Completed
Push — master ( 5061b6...54eaec )
by Michael
12:20 queued 12:16
created

xoops_module_install_smilies()   B

Complexity

Conditions 7
Paths 8

Size

Total Lines 31
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 22
nc 8
nop 1
dl 0
loc 31
rs 8.6346
c 0
b 0
f 0
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
use Xmf\Database\TableLoad;
13
14
/**
15
 * smilies module - install supplement for smilies module
16
 *
17
 * @copyright 2015-2019 XOOPS Project (https://xoops.org)
18
 * @license   GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
19
 * @package   smilies
20
 * @since     2.6.0
21
 * @author    Richard Griffith <[email protected]>
22
 */
23
24
/**
25
 * xoops_module_install_smilies - install supplement for smilies module
26
 *
27
 * @param object $module module object
28
 *
29
 * @return boolean true on success
30
 */
31
function xoops_module_install_smilies($module)
32
{
33
    $xoops = Xoops::getInstance();
34
    $uploadDirectory = $xoops->path('uploads/smilies');
35
    if (!mkdir($uploadDirectory, 0755, true) && !is_dir($uploadDirectory)) {
36
        $module->setErrors('Failed to create directory uploads/smilies');
37
        return false;
38
    }
39
    $mediaPath = $xoops->path('modules/smilies/media');
40
    $directory = dir($mediaPath);
41
    while ($filename = $directory->read()) {
42
        $mediaFilename = $mediaPath . '/' . $filename;
43
        if (is_file($mediaFilename)) {
44
            $target = $uploadDirectory . '/' . $filename;
45
            if (!copy($mediaFilename, $target)) {
46
                $module->setErrors("Failed copying: {$filename}");
47
                return false;
48
            }
49
            $module->setMessage("Copying media: {$filename}");
50
        }
51
    }
52
    $directory->close();
53
54
    $module->setMessage('Loading smilies table');
55
    $countInserted = TableLoad::loadTableFromYamlFile('smilies', dirname(__DIR__) . '/sql/smiliesdata.yml');
56
57
    if($countInserted < 1) {
58
        $module->setErrors('Loading smilies table failed');
59
        return false;
60
    }
61
    return true;
62
}
63