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


/**
 * Installer for the system-module
 *
 * @package module_dashboard
 */
class class_installer_dashboard extends class_installer_base implements interface_installer {

    private $strContentLanguage;

	public function __construct() {

        $this->objMetadata = new class_module_packagemanager_metadata();
        $this->objMetadata->autoInit(uniStrReplace(array(DIRECTORY_SEPARATOR."installer", _realpath_), array("", ""), __DIR__));

        $this->setArrModuleEntry("moduleId", _dashboard_module_id_);
		parent::__construct();

		//set the correct language
		$this->strContentLanguage = $this->objSession->getAdminLanguage();
	}


	public function install() {
	    $strReturn = "";


		//dashboard & widgets ---------------------------------------------------------------------------
		$strReturn .= "Installing table dashboard...\n";

		$arrFields = array();
		$arrFields["dashboard_id"] 			= array("char20", false);
		$arrFields["dashboard_column"]		= array("char254", true);
		$arrFields["dashboard_user"] 		= array("char20", true);
		$arrFields["dashboard_aspect"] 	    = array("char254", true);
		$arrFields["dashboard_class"] 	    = array("char254", true);
		$arrFields["dashboard_content"] 	= array("text", true);

		if(!$this->objDB->createTable("dashboard", $arrFields, array("dashboard_id")))
			$strReturn .= "An error occured! ...\n";
        //the dashboard
        $this->registerModule("dashboard", _dashboard_module_id_, "", "class_module_dashboard_admin.php", $this->objMetadata->getStrVersion(), false, "", "class_module_dashboard_admin_xml.php");

        //up till now, the default widgets are still missing - create them.
        $arrUsers = class_module_user_user::getAllUsers();
        foreach($arrUsers as $objOneUser) {
            $objDashboard = new class_module_dashboard_widget();
            $objDashboard->createInitialWidgetsForUser($objOneUser->getSystemid());
        }

        return $strReturn;
	}


	public function update() {
	    $strReturn = "";
        //check installed version and to which version we can update
        $arrModul = class_module_system_module::getPlainModuleData($this->objMetadata->getStrTitle(), false);

        $strReturn .= "Version found:\n\t Module: ".$arrModul["module_name"].", Version: ".$arrModul["module_version"]."\n\n";

        $arrModul = class_module_system_module::getPlainModuleData($this->objMetadata->getStrTitle(), false);
        if($arrModul["module_version"] == "3.4.2") {
            $strReturn .= $this->update_342_3491();
            $this->objDB->flushQueryCache();
        }

        $arrModul = class_module_system_module::getPlainModuleData($this->objMetadata->getStrTitle(), false);
        if($arrModul["module_version"] == "3.4.9.1") {
            $strReturn .= $this->update_3491_3492();
            $this->objDB->flushQueryCache();
        }

        return $strReturn."\n\n";
	}


    private function update_342_3491() {
        $strReturn = "Updating 3.4.9 to 3.4.9.1...\n";

        $strReturn .= "Updating model-classes...\n";

        $strReturn .= "Dashboard\n";
        $arrRows = $this->objDB->getPArray("SELECT system_id FROM "._dbprefix_."dashboard, "._dbprefix_."system WHERE system_id = dashboard_id", array());
        foreach($arrRows as $arrOneRow) {
            $strQuery = "UPDATE "._dbprefix_."system SET system_class = ? where system_id = ?";
            $this->objDB->_pQuery($strQuery, array( 'class_module_dashboard_widget', $arrOneRow["system_id"] ) );
        }

        //drop widget id
        //add class, content
        $strReturn .= "Updating dashboard table...\n";
        $strQuery = "ALTER TABLE ".$this->objDB->encloseTableName(_dbprefix_."dashboard")."
                            ADD ".$this->objDB->encloseColumnName("dashboard_class")." ".$this->objDB->getDatatype("char254")." NULL,
                            ADD ".$this->objDB->encloseColumnName("dashboard_content")." ".$this->objDB->getDatatype("text")." NULL";
        if(!$this->objDB->_pQuery($strQuery, array()))
            $strReturn .= "An error occured! ...\n";

        $strReturn .= "Migrating existing records...\n";
        $arrWidgetContent = $this->objDB->getPArray("SELECT * FROM "._dbprefix_."adminwidget", array());

        foreach($arrWidgetContent as $arrOneWidget) {

            $strQuery = "UPDATE "._dbprefix_."dashboard
                            SET dashboard_class = ?,
                                dashboard_content = ?
                          WHERE dashboard_widgetid = ?";

            $this->objDB->_pQuery($strQuery, array($arrOneWidget["adminwidget_class"], $arrOneWidget["adminwidget_content"], $arrOneWidget["adminwidget_id"]), array(true, false));

            //delete old records
            $this->objDB->_pQuery("DELETE FROM "._dbprefix_."adminwidget WHERE adminwidget_id = ?", array($arrOneWidget["adminwidget_id"]));
            $this->deleteSystemRecord($arrOneWidget["adminwidget_id"]);

            $strReturn .= "Migrated and deleted dashboard entry ".$arrOneWidget["adminwidget_id"]."\n";
        }


        $strQuery = "ALTER TABLE ".$this->objDB->encloseTableName(_dbprefix_."dashboard")."
                            DROP ".$this->objDB->encloseColumnName("dashboard_widgetid")." ";
        if(!$this->objDB->_pQuery($strQuery, array()))
            $strReturn .= "An error occured! ...\n";

        $strQuery = "DROP TABLE ".$this->objDB->encloseTableName(_dbprefix_."adminwidget")."";
        if(!$this->objDB->_pQuery($strQuery, array()))
            $strReturn .= "An error occured! ...\n";

        $this->objDB->flushQueryCache();

        $strReturn .= "Moving all dashboard entries to the correct module-node\n";
        $arrWidgets = class_module_dashboard_widget::getAllWidgets();
        foreach($arrWidgets as $objOneWidget)
            $objOneWidget->updateObjectToDb(_dashboard_module_id_);


        $strReturn .= "Updating module-versions...\n";
        $this->updateModuleVersion("dashboard", "3.4.9.1");
        return $strReturn;
    }


    private function update_3491_3492() {
        $strReturn = "Updating 3.4.9.1 to 3.4.9.2...\n";

        $strReturn .= "Updating widget db-structure...\n";
        $arrUsers = class_module_user_user::getAllUsers();
        $arrAspects = class_module_system_aspect::getAllAspects();


        foreach($arrUsers as $objOneUser) {
            $strReturn .= "  user: ".$objOneUser->getStrUsername()."\n";
            foreach($arrAspects as $objOneAspect) {
                $strReturn .= "    aspect: ".$objOneAspect->getStrName()."\n";

                $arrParams = array($objOneUser->getSystemid(), $objOneAspect->getSystemid());

                $strAspectWhere = " AND dashboard_aspect = ? ";
                if($objOneAspect->getBitDefault()) {
                    $strAspectWhere = " AND ( dashboard_aspect = ? OR dashboard_aspect IS NULL OR dashboard_aspect LIKE ? OR dashboard_aspect = '' ) ";
                    $arrParams[] = $objOneAspect->getSystemid();
                }

                $strQuery = "SELECT system_id
                              FROM "._dbprefix_."dashboard,
                                   "._dbprefix_."system
                             WHERE dashboard_id = system_id
                               AND dashboard_user = ?
                               ".$strAspectWhere;

                $arrRows = $this->objDB->getPArray($strQuery, $arrParams);
                foreach($arrRows as $arrOneRow) {
                    $objWidget = new class_module_dashboard_widget($arrOneRow["system_id"]);

                    if($objWidget->getStrClass() != "") {
                        $strReturn .= "     updating widget ".$objWidget->getSystemid()."\n";
                        $objWidget->updateObjectToDb(class_module_dashboard_widget::getWidgetsRootNodeForUser($objOneUser->getSystemid(), $objOneAspect->getSystemid()));
                    }
                }


            }

        }


        $strReturn .= "Updating module-versions...\n";
        $this->updateModuleVersion("dashboard", "3.4.9.2");
        return $strReturn;
    }

}
<commit_msg>NEW: the dashboard is visible in the navigation<commit_after><?php
/*"******************************************************************************************************
*   (c) 2004-2006 by MulchProductions, www.mulchprod.de                                                 *
*   (c) 2007-2012 by Kajona, www.kajona.de                                                              *
*       Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt                                 *
*-------------------------------------------------------------------------------------------------------*
*	$Id$                                        *
********************************************************************************************************/


/**
 * Installer for the system-module
 *
 * @package module_dashboard
 */
class class_installer_dashboard extends class_installer_base implements interface_installer {

    private $strContentLanguage;

	public function __construct() {

        $this->objMetadata = new class_module_packagemanager_metadata();
        $this->objMetadata->autoInit(uniStrReplace(array(DIRECTORY_SEPARATOR."installer", _realpath_), array("", ""), __DIR__));

        $this->setArrModuleEntry("moduleId", _dashboard_module_id_);
		parent::__construct();

		//set the correct language
		$this->strContentLanguage = $this->objSession->getAdminLanguage();
	}


	public function install() {
	    $strReturn = "";


		//dashboard & widgets ---------------------------------------------------------------------------
		$strReturn .= "Installing table dashboard...\n";

		$arrFields = array();
		$arrFields["dashboard_id"] 			= array("char20", false);
		$arrFields["dashboard_column"]		= array("char254", true);
		$arrFields["dashboard_user"] 		= array("char20", true);
		$arrFields["dashboard_aspect"] 	    = array("char254", true);
		$arrFields["dashboard_class"] 	    = array("char254", true);
		$arrFields["dashboard_content"] 	= array("text", true);

		if(!$this->objDB->createTable("dashboard", $arrFields, array("dashboard_id")))
			$strReturn .= "An error occured! ...\n";
        //the dashboard
        $this->registerModule("dashboard", _dashboard_module_id_, "", "class_module_dashboard_admin.php", $this->objMetadata->getStrVersion(), true, "", "class_module_dashboard_admin_xml.php");

        //up till now, the default widgets are still missing - create them.
        $arrUsers = class_module_user_user::getAllUsers();
        foreach($arrUsers as $objOneUser) {
            $objDashboard = new class_module_dashboard_widget();
            $objDashboard->createInitialWidgetsForUser($objOneUser->getSystemid());
        }

        return $strReturn;
	}


	public function update() {
	    $strReturn = "";
        //check installed version and to which version we can update
        $arrModul = class_module_system_module::getPlainModuleData($this->objMetadata->getStrTitle(), false);

        $strReturn .= "Version found:\n\t Module: ".$arrModul["module_name"].", Version: ".$arrModul["module_version"]."\n\n";

        $arrModul = class_module_system_module::getPlainModuleData($this->objMetadata->getStrTitle(), false);
        if($arrModul["module_version"] == "3.4.2") {
            $strReturn .= $this->update_342_3491();
            $this->objDB->flushQueryCache();
        }

        $arrModul = class_module_system_module::getPlainModuleData($this->objMetadata->getStrTitle(), false);
        if($arrModul["module_version"] == "3.4.9.1") {
            $strReturn .= $this->update_3491_3492();
            $this->objDB->flushQueryCache();
        }

        return $strReturn."\n\n";
	}


    private function update_342_3491() {
        $strReturn = "Updating 3.4.9 to 3.4.9.1...\n";

        $strReturn .= "Updating model-classes...\n";

        $strReturn .= "Dashboard\n";
        $arrRows = $this->objDB->getPArray("SELECT system_id FROM "._dbprefix_."dashboard, "._dbprefix_."system WHERE system_id = dashboard_id", array());
        foreach($arrRows as $arrOneRow) {
            $strQuery = "UPDATE "._dbprefix_."system SET system_class = ? where system_id = ?";
            $this->objDB->_pQuery($strQuery, array( 'class_module_dashboard_widget', $arrOneRow["system_id"] ) );
        }

        //drop widget id
        //add class, content
        $strReturn .= "Updating dashboard table...\n";
        $strQuery = "ALTER TABLE ".$this->objDB->encloseTableName(_dbprefix_."dashboard")."
                            ADD ".$this->objDB->encloseColumnName("dashboard_class")." ".$this->objDB->getDatatype("char254")." NULL,
                            ADD ".$this->objDB->encloseColumnName("dashboard_content")." ".$this->objDB->getDatatype("text")." NULL";
        if(!$this->objDB->_pQuery($strQuery, array()))
            $strReturn .= "An error occured! ...\n";

        $strReturn .= "Migrating existing records...\n";
        $arrWidgetContent = $this->objDB->getPArray("SELECT * FROM "._dbprefix_."adminwidget", array());

        foreach($arrWidgetContent as $arrOneWidget) {

            $strQuery = "UPDATE "._dbprefix_."dashboard
                            SET dashboard_class = ?,
                                dashboard_content = ?
                          WHERE dashboard_widgetid = ?";

            $this->objDB->_pQuery($strQuery, array($arrOneWidget["adminwidget_class"], $arrOneWidget["adminwidget_content"], $arrOneWidget["adminwidget_id"]), array(true, false));

            //delete old records
            $this->objDB->_pQuery("DELETE FROM "._dbprefix_."adminwidget WHERE adminwidget_id = ?", array($arrOneWidget["adminwidget_id"]));
            $this->deleteSystemRecord($arrOneWidget["adminwidget_id"]);

            $strReturn .= "Migrated and deleted dashboard entry ".$arrOneWidget["adminwidget_id"]."\n";
        }


        $strQuery = "ALTER TABLE ".$this->objDB->encloseTableName(_dbprefix_."dashboard")."
                            DROP ".$this->objDB->encloseColumnName("dashboard_widgetid")." ";
        if(!$this->objDB->_pQuery($strQuery, array()))
            $strReturn .= "An error occured! ...\n";

        $strQuery = "DROP TABLE ".$this->objDB->encloseTableName(_dbprefix_."adminwidget")."";
        if(!$this->objDB->_pQuery($strQuery, array()))
            $strReturn .= "An error occured! ...\n";

        $this->objDB->flushQueryCache();

        $strReturn .= "Moving all dashboard entries to the correct module-node\n";
        $arrWidgets = class_module_dashboard_widget::getAllWidgets();
        foreach($arrWidgets as $objOneWidget)
            $objOneWidget->updateObjectToDb(_dashboard_module_id_);


        $strReturn .= "Updating module-versions...\n";
        $this->updateModuleVersion("dashboard", "3.4.9.1");
        return $strReturn;
    }


    private function update_3491_3492() {
        $strReturn = "Updating 3.4.9.1 to 3.4.9.2...\n";

        $strReturn .= "Updating widget db-structure...\n";
        $arrUsers = class_module_user_user::getAllUsers();
        $arrAspects = class_module_system_aspect::getAllAspects();


        $strReturn .= "Enabling dashboard in navigation...\n";
        $objModule = class_module_system_module::getModuleByName("dashboard");
        $objModule->setIntNavigation(1);
        $objModule->updateObjectToDb();


        foreach($arrUsers as $objOneUser) {
            $strReturn .= "  user: ".$objOneUser->getStrUsername()."\n";
            foreach($arrAspects as $objOneAspect) {
                $strReturn .= "    aspect: ".$objOneAspect->getStrName()."\n";

                $arrParams = array($objOneUser->getSystemid(), $objOneAspect->getSystemid());

                $strAspectWhere = " AND dashboard_aspect = ? ";
                if($objOneAspect->getBitDefault()) {
                    $strAspectWhere = " AND ( dashboard_aspect = ? OR dashboard_aspect IS NULL OR dashboard_aspect LIKE ? OR dashboard_aspect = '' ) ";
                    $arrParams[] = $objOneAspect->getSystemid();
                }

                $strQuery = "SELECT system_id
                              FROM "._dbprefix_."dashboard,
                                   "._dbprefix_."system
                             WHERE dashboard_id = system_id
                               AND dashboard_user = ?
                               ".$strAspectWhere;

                $arrRows = $this->objDB->getPArray($strQuery, $arrParams);
                foreach($arrRows as $arrOneRow) {
                    $objWidget = new class_module_dashboard_widget($arrOneRow["system_id"]);

                    if($objWidget->getStrClass() != "") {
                        $strReturn .= "     updating widget ".$objWidget->getSystemid()."\n";
                        $objWidget->updateObjectToDb(class_module_dashboard_widget::getWidgetsRootNodeForUser($objOneUser->getSystemid(), $objOneAspect->getSystemid()));
                    }
                }


            }

        }


        $strReturn .= "Updating module-versions...\n";
        $this->updateModuleVersion("dashboard", "3.4.9.2");
        return $strReturn;
    }

}

{'fraction_non_alphanumeric': 0.18533855623950757, 'fraction_numerical': 0.010576385002797985, 'mean_word_length': 2.329172876304024, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 159, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 12, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5392619', 'n_tokens_mistral': 5186, 'n_tokens_neox': 4894, 'n_words': 822}