Completed
Branch develop (bb7c03)
by
unknown
34:20
created

modBlockedLog   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 122
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 67 4
A alreadyUsed() 0 10 2
B remove() 0 24 2
1
<?php
2
/* Copyright (C) 2017   Laurent Destailleur  <[email protected]>
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
/**
19
 * 	\defgroup   blockedlog   Module BlockedLog
20
 *  \brief      Add a log into a block chain for some actions.
21
 *  \file       htdocs/core/modules/modBlockedLog.class.php
22
 *  \ingroup    blockedlog
23
 *  \brief      Description and activation file for module BlockedLog
24
 */
25
include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
26
27
/**
28
 *	Class to describe a BlockedLog module
29
 */
30
class modBlockedLog extends DolibarrModules
31
{
32
    /**
33
	 *   Constructor. Define names, constants, directories, boxes, permissions
34
	 *
35
	 *   @param      DoliDB		$db      Database handler
36
     */
37
    function __construct($db)
38
    {
39
    	global $langs,$conf,$mysoc;
40
41
        $this->db = $db;
42
        $this->numero = 3200;
43
44
		// Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
45
		// It is used to group modules in module setup page
46
        $this->family = "base";
47
        // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
48
        $this->name = preg_replace('/^mod/i','',get_class($this));
49
        $this->description = "Enable a log on some business events into a non reversible log. This module may be mandatory for some countries.";
50
		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
51
        $this->version = 'experimental';
52
        // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
53
        $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
54
        // Where to store the module in setup page (0=common,1=interface,2=others,3=very specific)
55
        $this->special = 2;
56
        // Name of image file used for this module.
57
        $this->picto='technic';
58
59
        // Data directories to create when module is enabled
60
        $this->dirs = array();
61
62
        // Config pages
63
        //-------------
64
        $this->config_page_url = array('blockedlog.php@blockedlog');
65
66
        // Dependancies
67
        //-------------
68
	    $this->hidden = false;	// A condition to disable module
69
	    $this->depends = array('always'=>'modFacture');	   // List of modules id that must be enabled if this module is enabled
1 ignored issue
show
Documentation Bug introduced by
It seems like array('always' => 'modFacture') of type array<string,string,{"always":"string"}> is incompatible with the declared type array<integer,string> of property $depends.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
70
        $this->requiredby = array();	                   // List of modules id to disable if this one is disabled
71
	    $this->conflictwith = array();	                   // List of modules id this module is in conflict with
72
        $this->langfiles = array('blockedlog');
73
74
        $this->warnings_activation = array();                     // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
75
        $this->warnings_activation_ext = array();                 // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
76
        $this->warnings_unactivation = array('FR'=>'BlockedLogAreRequiredByYourCountryLegislation');
77
78
        // Currently, activation is not automatic because only companies (in France) making invoices to non business customers must
79
        // enable this module.
80
        // It is automatic only if $conf->global->BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY is on.
81
        if (! empty($conf->global->BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY))
82
        {
83
        	$this->automatic_activation = array('FR'=>'BlockedLogActivatedBecauseRequiredByYourCountryLegislation');
84
        }
85
86
        $this->always_enabled = !empty($conf->blockedlog->enabled) && !empty($conf->global->BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY) && in_array($mysoc->country_code, explode(',', $conf->global->BLOCKEDLOG_DISABLE_NOT_ALLOWED_FOR_COUNTRY));
87
88
        // Constants
89
        //-----------
90
        $this->const = array();
91
92
        // New pages on tabs
93
        // -----------------
94
        $this->tabs = array();
95
96
        // Boxes
97
        //------
98
        $this->boxes = array();
99
100
        // Main menu entries
101
        //------------------
102
        $this->menu = array();
103
    }
104
105
    /**
106
     * Check if module was already used before unactivation linked to warnings_unactivation property
107
     */
108
    function alreadyUsed() {
109
110
    	$res = $this->db->query("SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."blockedlog");
111
    	if($res!==false) {
112
    		$obj = $this->db->fetch_object($res);
113
    		return ($obj->nb > 0);
114
    	}
115
116
    	return false;
117
    }
118
119
    /**
120
	 * Function called when module is disabled.
121
	 * The remove function removes tabs, constants, boxes, permissions and menus from Dolibarr database.
122
	 * Data directories are not deleted
123
	 *
124
	 * @param      string	$options    Options when enabling module ('', 'noboxes')
125
	 * @return     int             		1 if OK, 0 if KO
126
	 */
127
    function remove($options = '') {
128
129
    	global $user;
130
131
    	require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
132
133
    	$object=new stdClass;
134
    	$object->id = 1;
135
    	$object->element = 'module';
136
    	$object->ref = 'module';
137
    	$object->date = time();
138
139
    	$b=new BlockedLog($this->db);
140
    	$b->setObjectData($object, 'MODULE_RESET', -1);
141
142
    	$res = $b->create($user);
143
    	if($res<=0) {
144
    		$this->error = $b->error;
145
    		return $res;
146
    	}
147
148
    	return $this->_remove(array(), $options);
149
150
    }
151
}
152