Jump To …

Dolibarr.php

We expect (but do not insist) the file to be PSR-compatible.

The name of the file must be $unique_name.php. If your name happens to be identical to another script, we will notify you and you must modify suitably.

The name of the class must be Netenberg_Script_$unique_name.

The class must derive from Netenberg_Script.

class Netenberg_Script_Dolibarr extends Netenberg_Script
{

This function is called as part of the actual installation process (Step 3).

$parameters is a dictionary that contains the values supplied by the user (Step 1) in addition to a few system-specific values. The full extent of this dictionary is (will be made) available in the guide.

    public function install($parameters)
    {

This is a singleton that you can use to access control panel-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $control_panel = Zend_Registry::get('control_panel');

This is a singleton that you can use to access operating system-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $operating_system = Zend_Registry::get('operating_system');

This is an abstracted cURL object. You may use it for the sake of simplicity and also for ease of debugging. The full extent of this singleton is (will be made) available in the guide.

        $curl = new Netenberg_cURL;

You are encouraged to employ the usage of steps as follows:

 $step = 0;

 log_('DEBUG', sprintf(_('Step %d'), ++$step));
 ...
 ...
 ...

 log_('DEBUG', sprintf(_('Step %d'), ++$step));
 ...
 ...
 ...
        $step = 0;

        $main_data_dir = sprintf(
            '%s/%s/documents',
            $parameters['document_root'],
            $parameters['directory']
        );

        $main_dir = sprintf(
            '%s/%s',
            $parameters['document_root'],
            $parameters['directory']
        );

        $main_url = sprintf(
            'http://%s/%s',
            $parameters['domain'],
            $parameters['directory']
        );

In this step, a fresh database is being created via the control panel singleton.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        list(
            $parameters['mysql_hostname'],
            $parameters['mysql_username'],
            $parameters['mysql_password'],
            $parameters['mysql_database']
        ) = $control_panel->insertMySQL();

In this step, the source archive is being downloaded and extracted to the desired directory via the control panel singleton.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $operating_system->transpose(
            'http://kaz.dl.sourceforge.net/project/dolibarr/Dolibarr%20ERP-CRM/3.5.2/dolibarr-3.5.2.zip',
            array(

Here contents of dolibarr-3.5.2/htdocs extracted to specified directory in the document root.

                'dolibarr-3.5.2/htdocs/*' => sprintf(
                    '%s/%s',
                    $parameters['document_root'],
                    $parameters['directory']
                ),

Here contents of dolibarr-3.5.2 extracted to Home Directory.

                'dolibarr-3.5.2/*' => sprintf(
                    '%s/%s',
                    $control_panel->getHome(),
                    $parameters['directory']
                ),
            )
        );

        log_('DEBUG', sprintf(_('Step %d'), ++$step));

In this step we htdocs directory is removed from Home Directory.

        $operating_system->rm(sprintf(
            '%s/%s/htdocs',
            $control_panel->getHome(),
            $parameters['directory']
        ), true);

$operating_system->mkdir() is a function used to create an empty directory in the specified path. You can use any number of $operating_system->mkdir() statements as required or as specified in installation guidelenes. $operating_system->mkdir() takes two mandatory arguments path to folder which is to be created and permission to the created folder.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));

This statement creates directory called documents in the specified path.

        $operating_system->mkdir(sprintf(
            '%s/%s/documents',
            $parameters['document_root'],
            $parameters['directory']
        ), 777);

$operating_system->touch() is a function used to create an empty file in the speicfied path. You can use any number of $operating_system->touch() statements as required or as specified in installation guidelenes. $operating_system->touch() takes only one mandatory argument path to file which is to be created.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));

This statement creates file called conf.php in the specified path

        $operating_system->touch(sprintf(
            '%s/%s/conf/conf.php',
            $parameters['document_root'],
            $parameters['directory']
        ));

$operating_system->chmod() used to set permissions

You can write any number of chmod statements as required or as instructed in the installation guidelines $operating_system->chmod() fucntion takes three mandatory arguments. path to the specified file/folder permissions i.e 777 for directory or may be 666 or 644 for a file etc. true (for recursive) or false (for non-recursive).

        log_('DEBUG', sprintf(_('Step %d'), ++$step));

In this step, permissions of assets directory has been changed to 777 i.e. read-write-execute permissions to all three user levels owner, group and others.

        if (!$control_panel->hassuEXEC()) {
            $operating_system->chmod(sprintf(
                '%s/%s/conf/conf.php',
                $parameters['document_root'],
                $parameters['directory']
            ), 777, false);
        }

$curl->request is a function used to send Request to the URL. $curl->request() takes 5 arguments, i.e. URL to which request has to be sent, METHOD i.e. GET or POST, POSTFIELDS, which is present only for POST method, otherwise an empty array, HTTP HEADERS, and OPTIONS.

In this step we are making a POST Request to the URL http://%s/%s/install/check.php, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/install/check.php',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(
                'action' => 'set',
                'selectlang' => 'auto',
                'testpost' => 'ok',
            ),
            array(),
            array()
        );

In this step we are making a POST Request to the URL http://%s/%s/install/fileconf.php?selectlang=auto, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/install/fileconf.php?selectlang=auto',
                $parameters['domain'],
                $parameters['directory']
            ),
            'GET',
            array(),
            array(),
            array()
        );

In this step we are making a POST Request to the URL http://%s/%s/install/etape1.php, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/install/etape1.php',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(
                'action' => 'set',

$parameters['mysql_hostname'] refers to MySQL Hostname.

                'db_host' => $parameters['mysql_hostname'],

$parameters['mysql_database'] refers to MySQL Database.

                'db_name' => $parameters['mysql_database'],

$parameters['mysql_password'] refers to MySQL Password.

                'db_pass' => $parameters['mysql_password'],
                'db_port' => '3306',

llx_ is the table prefix prefixed with names of MySQL tables which will be created during installation.

                'db_prefix' => 'llx_',
                'db_type' => 'mysqli',

$parameters['mysql_username'] refers to MySQL Username.

                'db_user' => $parameters['mysql_username'],
                'main_data_dir' => $main_data_dir,
                'main_dir' => $main_dir,
                'main_url' => $main_url,
                'selectlang' => 'en_US',
                'testpost' => 'ok',
            ),
            array(),
            array()
        );

In this step we are making a POST Request to the URL http://%s/%s/install/etape2.php, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/install/etape2.php',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(
                'action' => 'set',
                'dolibarr_main_db_character_set' => 'utf8',
                'dolibarr_main_db_collation' => 'utf8_general_ci',
                'selectlang' => 'en_US',
                'testpost' => 'ok',
            ),
            array(),
            array()
        );

In this step we are making a POST Request to the URL http://%s/%s/install/etape4.php, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/install/etape4.php',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(
                'action' => 'set',
                'selectlang' => 'en_US',
                'testpost' => 'ok',
            ),
            array(),
            array()
        );

In this step we are making a POST Request to the URL http://%s/%s/install/etape5.php, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        list(
            $curl_exec, $curl_errno, $curl_error, $curl_getinfo
        ) = $curl->request(
            sprintf(
                'http://%s/%s/install/etape5.php',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(
                'action' => 'set',

$parameters['login'] refers to value entered in the Username Field before the actual installation process starts.

                'login' => $parameters['login'],

$parameters['pass'] refers to value entered in the Password Field before the actual installation process starts.

                'pass' => $parameters['pass'],

$parameters['pass_verif'] refers to value entered in the Password (Repeat) Field before the actual installation process starts.

                'pass_verif' => $parameters['pass_verif'],
                'selectlang' => 'en_US',
                'testpost' => 'ok',
            ),
            array(),
            array()
        );

In this step, we check if the installation was successful.

        if (strpos($curl_exec[1], 'This installation is complete') !== false) {

This indicates a success status (and is mandatory).

            log_('DEBUG', 'Success');

This allows the core system to register this installation within the user account (and is mandatory).

            return parent::install($parameters);
        }

This indicates a failure status (and is mandatory).

        log_('DEBUG', 'Failure');

        return false;
    }

This function provides the category (and is mandatory).

    public function getCategory()
    {
        return _('ERP');
    }

This function provides the description (and is mandatory).

    public function getDescription()
    {
        return _('Dolibarr ERP & CRM is a modern and easy to use web software to manage your business (contacts, invoices, orders, products, stocks, agenda, emailings, etc.)');
    }

This function provides the details of an installed copy (and is mandatory).

$parameters is a dictionary that contains domain, directory, and document_root.

    public function getDetails($parameters)
    {
        $filefunc_inc_php = sprintf(
            '%s/%s/filefunc.inc.php',
            $parameters['document_root'],
            $parameters['directory']
        );
        if (!is_file($filefunc_inc_php)) {
            return false;
        }
        $contents = file_get_contents($filefunc_inc_php);

This statemnt performs a regular expression match on version of the installed copy on the contents of filefunc.inc.php file.

        preg_match('#DOL_VERSION\',\'([\d+\.]+)\'#', $contents, $version);

        return array(
            'version' => $version[1],
        );
    }

This function builds the form presented to the user (Step 1) (and is mandatory). It is built upon the Zend_Form component of Zend Framework.

    public function getForm()
    {

This is a singleton that you can use to access control panel-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $control_panel = Zend_Registry::get('control_panel');

This is an abstracted form object derived from Zend_Form. The full extent of this class is (will be made) available in the guide.

        $form = new Netenberg_Form();

This statement adds the domain selector (and is mandatory).

        $form->addElement('select', 'domain', array(
            'label' => _('Domain'),
            'multiOptions' => $control_panel->getDomains(),
            'required' => true,
        ));

This statement adds the directory selector (and is mandatory).

        $form->addElement('text', 'directory', array(
            'description' => _('Leave this field empty if you want to install in the web root for the domain you\'ve selected (i.e., http://domain.com/ ). If you\'d like to install in a subdirectory, please enter the path to the directory relative to the web root for your domain. The final destination subdirectory should not exist, but all others can exist (e.g., http://domain.com/some/sub/directory - In this case, "directory" should not already exist).'),
            'filters' => array(new Netenberg_Filter_Directory()),
            'label' => _('Directory'),
            'validators' => array(new Netenberg_Validate_Directory()),
        ));

This statement adds the username textfield (and is mandatory).

        $form->addElement('text', 'login', array(
            'label' => _('Username'),
            'required' => true,
        ));

This statement adds the password textfield (and is mandatory).

        $form->addElement('password', 'pass', array(
            'label' => _('Password'),
            'required' => true,
        ));

This statement adds the password repeat textfield (and is mandatory).

        $form->addElement('password', 'pass_verif', array(
            'label' => _('Password (Repeat)'),
            'required' => true,

This validator statement checks whether this field is identical to value of Password Textfield.

            'validators' => array(
                array('Identical', false, array(
                    'token' => 'pass',
                )),
            ),
        ));

This statement adds the Submit button to the form (and is mandatory).

        $form->addElement('button', 'submit');

This statement adds the Reset button to the form (and is mandatory).

        $form->addElement('button', 'reset');

This statement places the domain and directory selectors under the display group Location Details.

        $form->addDisplayGroup(
            array('domain', 'directory'),
            'location_details',
            array(
                'decorators' => $form->getDefaultGroupDecorator(),
                'disableLoadDefaultDecorators' => true,
                'legend' => 'Location Details',
            )
        );

This statement places login, pass and pass_verif under the display group Administrator Details.

        $form->addDisplayGroup(
            array('login', 'pass', 'pass_verif'),
            'administrator_details',
            array(
                'decorators' => $form->getDefaultGroupDecorator(),
                'disableLoadDefaultDecorators' => true,
                'legend' => _('Administrator Details'),
            )
        );

This statement places the Submit and Reset buttons in end of the form.

        $form->addDisplayGroup(
            array('submit', 'reset'),
            'buttons',
            array(
                'decorators' => $form->getButtonGroupDecorator(),
                'disableLoadDefaultDecorators' => true,
            )
        );

        return $form;
    }

This function provides the image (and is mandatory).

    public function getImage()
    {
        return 'http://www.dolibarr.org/templates/dolibarr/images/bg2.png';
    }

This function provides the post-installation overview (and is mandatory).

$parameters is a dictionary that contains the values supplied by the user like domain, directory and username and/or password and/or email etc.

    public function getItems($parameters)
    {
        return array(

This statement provides the URL for Backend page. Backend page is a login-page which is used to login into Administrator's Account.

            _('Backend') => array(
                sprintf(
                    '<a href="http://%s/%s/admin" target="_blank">http://%s/%s/admin</a>',
                    $parameters['domain'],
                    $parameters['directory'],
                    $parameters['domain'],
                    $parameters['directory']
                ),
                sprintf(_('Username: %s'), $parameters['login']),
                sprintf(_('Password: %s'), $parameters['pass']),
            ),
        );
    }

This function provides the name (and is mandatory). The name must be unique.

    public function getName()
    {
       return 'Dolibarr';
    }

This function provides the requirements (and is mandatory).

    public function getRequirements()
    {

This is a singleton that you can use to access control panel-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $control_panel = Zend_Registry::get('control_panel');

        $apache = $control_panel->getApache();
        $mysql = $control_panel->getMySQL();
        $php = $control_panel->getPHP();

        return array(

This statement checks whether enough space is available in your account to install this script.

            'Disk Space' => (
                $control_panel->getSize() >= $this->getSize()
            )? true: false,

This statement checks whether installed Apache's version is greater than 1.

            'Apache 1+' => (
                strpos($apache, 'Apache/1') !== false
                or
                strpos($apache, 'Apache/2') !== false
            )? true: false,

This statement checks whether installed MySQL's version is greater than 4.1.

            'MySQL 4.1+' => (
                strpos($mysql, 'Distrib 4.1') !== false
                or
                strpos($mysql, 'Distrib 5') !== false
            )? true: false,

This statement checks whether installed PHP's version is greater than 5.2.4

            'PHP 5.0+' => (preg_match(
                '#PHP Version\s*=>\s*(5\.[0-9])#', $php
            ) === 1)? true: false,

This statement checks whether value of memory_limit directive in php.ini is greater than 64MB or not

            'PHP :: memory_limit' => (
                $value == -1 or $value >= (64 * 1024 * 1024)
            )? true: false,

This statement checks whether session_support extension is enabled or not for the installed version of PHP.

            'PHP :: session' => (preg_match(
                '#Session Support\s*=>\s*enabled#', $php
            ) === 1)? true: false,
        );
    }

This function provides the size (in bytes) (and is mandatory).

    public function getSize()
    {
        return 55574528;
    }

This function provides the slug (and is mandatory). The slug must be unique.

    public function getSlug()
    {
        return 'dolibarr';
    }

This function provides the URLs (and is mandatory).

We expect(but do not insist)URLs for four pages to be part of the array. They are URLs of Home, Community, Documentation and Support or Forum pages.

    public function getUrls()
    {
        return array(
            _('Home') => 'http://www.dolibarr.org',
            _('Documentation') => 'http://www.dolibarr.org/documentation',
            _('Support') => 'http://www.dolibarr.org/forum',

        );
    }

This function provides the version (and is mandatory).

    public function getVersion()
    {
        return '3.5.2';
    }

This function is called as part of the actual uninstallation process

$parameters is a dictionary that contains the values supplied by the user in addition to a few system-specific values. The full extent of this dictionary is (will be made) available in the guide.

    public function uninstall($parameters)
    {

This is a singleton that you can use to access control panel-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $control_panel = Zend_Registry::get('control_panel');

This is a singleton that you can use to access operating system-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $operating_system = Zend_Registry::get('operating_system');

        $conf_php = sprintf(
            '%s/%s/conf/conf.php',
            $parameters['document_root'],
            $parameters['directory']
        );
        if (!is_file($conf_php)) {
            return false;
        }
        $contents = file_get_contents($conf_php);

This statement performs a regular expression match to fetch database name from the contents of conf.php

        preg_match(
            '#dolibarr_main_db_name\s*=\s*\'([^\']*)#', $contents, $database
        );

This statement performs a regular expression match to fetch database username from the contents of wp-config.php

        preg_match(
            '#dolibarr_main_db_user\s*=\s*\'([^\']*)#',
            $contents,
            $mysql_username
        );

In this step, we remove the database via the control panel singleton.

        $control_panel->deleteMySQL($mysql_username[1], $database[1]);

        $operating_system->dispose(sprintf(
            '%s/%s', $parameters['document_root'], $parameters['directory']
        ));

In this step, we remove the directory via the operating system singleton.

        $operating_system->dispose(sprintf(
            '%s/%s', $parameters['document_root'], $parameters['directory']
        ));

This allows the core system to unregister this installation within the user account (and is mandatory).

        return parent::uninstall($parameters);
    }
}