Source of file SystemtaskDbimport.php

Size: 3,718 Bytes - Last Modified: 2016-05-18T03:08:27+02:00

buildproject/core/module_system/admin/systemtasks/SystemtaskDbimport.php

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
<?php
/*"******************************************************************************************************
*   (c) 2004-2006 by MulchProductions, www.mulchprod.de                                                 *
*   (c) 2007-2016 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
*-------------------------------------------------------------------------------------------------------*
*   $Id$                                        *
********************************************************************************************************/

namespace Kajona\System\Admin\Systemtasks;

use Kajona\System\System\Carrier;
use Kajona\System\System\Filesystem;
use Kajona\System\System\SystemModule;


/**
 * Restores the database from the filesystem using the current db-driver
 *
 * @package module_system
 */
class SystemtaskDbimport extends SystemtaskBase implements AdminSystemtaskInterface
{


    /**
     * @inheritdoc
     */
    public function getGroupIdentifier()
    {
        return "database";
    }

    /**
     * @inheritdoc
     */
    public function getStrInternalTaskName()
    {
        return "dbimport";
    }

    /**
     * @inheritdoc
     */
    public function getStrTaskName()
    {
        return $this->getLang("systemtask_dbimport_name");
    }

    /**
     * @inheritdoc
     */
    public function executeTask()
    {
        if (!SystemModule::getModuleByName("system")->rightRight2()) {
            return $this->getLang("commons_error_permissions");
        }

        if (Carrier::getInstance()->getObjDB()->importDb($this->getParam("dbImportFile"))) {
            return $this->objToolkit->getTextRow($this->getLang("systemtask_dbimport_success"));
        }
        else {
            return $this->objToolkit->getTextRow($this->getLang("systemtask_dbimport_error"));
        }
    }

    /**
     * @inheritdoc
     */
    public function getAdminForm()
    {
        $strReturn = "";
        //show dropdown to select db-dump
        $objFilesystem = new Filesystem();
        $arrFiles = $objFilesystem->getFilelist(_projectpath_."/dbdumps/", array(".sql", ".gz"));
        $arrOptions = array();
        foreach ($arrFiles as $strOneFile) {
            $arrDetails = $objFilesystem->getFileDetails(_projectpath_."/dbdumps/".$strOneFile);

            $strTimestamp = "";
            if (uniStrpos($strOneFile, "_") !== false) {
                $strTimestamp = uniSubstr($strOneFile, uniStrrpos($strOneFile, "_") + 1, (uniStrpos($strOneFile, ".") - uniStrrpos($strOneFile, "_")));
            }

            if (uniStrlen($strTimestamp) > 9 && is_numeric($strTimestamp)) {
                $arrOptions[$strOneFile] = $strOneFile." (".bytesToString($arrDetails["filesize"]).")"
                    ."<br />".$this->getLang("systemtask_dbimport_datefilename")." ".timeToString($strTimestamp)
                    ."<br />".$this->getLang("systemtask_dbimport_datefileinfo")." ".timeToString($arrDetails['filechange']);
            }

            else {
                $arrOptions[$strOneFile] = $strOneFile." (".bytesToString($arrDetails["filesize"]).")"
                    ."<br />".$this->getLang("systemtask_dbimport_datefileinfo")." ".timeToString($arrDetails['filechange']);
            }
        }

        $strReturn .= $this->objToolkit->formInputRadiogroup("dbImportFile", $arrOptions, $this->getLang("systemtask_dbimport_file"));

        return $strReturn;
    }

    /**
     * @inheritdoc
     */
    public function getSubmitParams()
    {
        return "&dbImportFile=".$this->getParam("dbImportFile");
    }
}