Call member function ColumnExists () to null

I am making a plugin for ILIAS and I am using this error when I try to call for anything related to the database. I include the dbupdate file in the config file so that I can update and modify it when developing the plugin.

(This is because I believe ILIAS only uses dbupdate when the plugin is installed.)

The code where it gives the error:

if(!$ilDB->tableColumnExists('rep_robj_xptg_data','id'))
{
    $ilDB->addTableColumn(
        'rep_robj_xptg_data',
        'id',
        array(
            'type'           => 'integer',
            'length'         => 4000
        )
    );
}

      

There are columns and IDs in the database. I believe this should work to be able to persist data to the database in the future.

Refresh

This is the code that "calls":

<?php

    include ("/Customizing/global/plugins/Services/Repository/RepositoryObject/Presentations2Go/sql/dbupdate.php");
    require_once('./Services/Component/classes/class.ilPluginConfigGUI.php');
    require_once('class.ilPresentations2GoPlugin.php');
    require_once('class.ilObjPresentations2Go.php');
    //require ("/Customizing/global/plugins/Services/Repository/RepositoryObject/Presentations2Go/sql/dbupdate.php");

    /**
     * Presentations2Go configuration user interface class
     *
     * @author Bonny van den Bovenkamp
     * @version $Id$
     *
     */
    class ilPresentations2GoConfigGUI extends ilPluginConfigGUI
    {
        /**
        * Handles all commmands, default is "configure"
        */
        function performCommand($cmd)
        {

            switch ($cmd)
            {
                case "configure":
                case "save":
                    $this->$cmd();
                    break;

            }
        }

        /**
         * Configure screen
         */
        function configure()
        {
            global $tpl;

            $form = $this->initConfigurationForm();
            $tpl->setContent($form->getHTML());
        }

        //
        // From here on, this is just an Presentations2Go implementation using
        // a standard form (without saving anything)
        //

        /**
         * Init configuration form.
         *
         * @return object form object
         */
        public function initConfigurationForm()
        {
            global $lng, $ilCtrl;

            $pl = $this->getPluginObject();

            include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
            $form = new ilPropertyFormGUI();

            // setting 1 (a checkbox)
            $cb = new ilCheckboxInputGUI($pl->txt("setting_1"), "setting_1");
            $form->addItem($cb);

            // setting 2 (text)
            $ti = new ilTextInputGUI($pl->txt("setting_2"), "setting_2");
            $ti->setRequired(true);
            $ti->setMaxLength(10);
            $ti->setSize(10);
            $form->addItem($ti);

            $form->addCommandButton("save", $lng->txt("save"));

            $form->setTitle($pl->txt("Presentations2Go configuration"));
            $form->setFormAction($ilCtrl->getFormAction($this));

            return $form;
        }

        /**
         * Save form input (currently does not save anything to db)
         *
         */
        public function save()
        {
            global $tpl, $lng, $ilCtrl;

            $pl = $this->getPluginObject();

            $form = $this->initConfigurationForm();
            if ($form->checkInput())
            {
                $set1 = $form->getInput("setting_1");
                $set2 = $form->getInput("setting_2");


                ilUtil::sendSuccess($pl->txt("saving_invoked"), true);
                $ilCtrl->redirect($this, "configure");
            }
            else
            {
                $form->setValuesByPost();
                $tpl->setContent($form->getHtml());
            }
        }

    }
    ?>

      

And this is the file called:

<?php


if(!$ilDB->tableColumnExists('rep_robj_xptg_data','id'))
{
    $ilDB->addTableColumn(
        'rep_robj_xptg_data',
        'id',
        array(
            'type'           => 'integer',
            'length'         => 4
        )
    );
}
if(!$ilDB->tableColumnExists('rep_robj_xptg_data','is_online'))
{
    $ilDB->addTableColumn(
        'rep_robj_xptg_data',
        'is_online',
        array(
            'type'           => 'integer',
            'length'         => 4
        )
    );
}
if(!$ilDB->tableColumnExists('rep_robj_xptg_data','option_one'))
{
    $ilDB->addTableColumn(
        'rep_robj_xptg_data',
        'option_one',
        array(
            'type'           => 'text',
            'length'         => 4
        )
    );
}
if(!$ilDB->tableColumnExists('rep_robj_xptg_data','option_two'))
{
    $ilDB->addTableColumn(
        'rep_robj_xptg_data',
        'option_two',
        array(
            'type'           => 'text',
            'length'         => 4
        )
    );
}
if(!$ilDB->tableColumnExists('rep_robj_xptg_data','option_three'))
{
    $ilDB->addTableColumn(
        'rep_robj_xptg_data',
        'option_three',
        array(
            'type'           => 'text',
            'length'         => 4
        )
    );
}
?>

      

+3


source to share


1 answer


I solved this by creating another class called ilconfig. it contains this very important part:

public function initDB() {
        global $ilDB;
        if (!$ilDB->tableExists($this->getTableName())) {
            $fields = array(
                'config_key' => array(
                    'type' => 'text',
                    'length' => 128,
                    'notnull' => true
                ),
                'config_value' => array(
                    'type' => 'clob',
                    'notnull' => false
                ),
            );
            $ilDB->createTable($this->getTableName(), $fields);
            $ilDB->addPrimaryKey($this->getTableName(), array( "config_key" ));
        }

        return true;
    }

      



I hope this helps other people trying to develop plugins in ILIAS!

+2


source







All Articles