Commit 9364ce61 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

🚜 feat(core) Adapting code to simplePlugin strict typing

issue #5956
parent 03c23260
......@@ -26,28 +26,28 @@ class SnapshotCreateDialog extends simplePlugin
{
public $aclCategory;
static function plInfo()
static function plInfo (): array
{
return array(
'plShortName' => 'SnapshotCreateDialog',
);
}
static function getAttributesInfo ()
static function getAttributesInfo (): array
{
return array(
'main' => array(
'name' => _('Creating an object snapshot'),
'attrs' => array(
new DisplayAttribute (
new DisplayAttribute(
_('Object'), _('DN of the object you are creating a snapshot of'),
'object_dn', FALSE
),
new DisplayAttribute (
new DisplayAttribute(
_('Timestamp'), _('Timestamp of this snapshot creation'),
'timestamp', FALSE
),
new TextAreaAttribute (
new TextAreaAttribute(
_('Reason'), _('Reason for creating this snapshot'),
'description', TRUE,
'',
......@@ -71,7 +71,7 @@ class SnapshotCreateDialog extends simplePlugin
*
* \param mixed $attr Attribute object or name (in this case it will be fetched from attributesAccess)
*/
function attrIsWriteable($attr)
function attrIsWriteable($attr): bool
{
global $ui;
......@@ -100,7 +100,7 @@ class SnapshotCreateDialog extends simplePlugin
return parent::renderAttributes($readOnly);
}
function execute ()
function execute (): string
{
$this->timestamp = date(_('Y-m-d, H:i:s'));
$str = parent::execute();
......@@ -113,7 +113,7 @@ class SnapshotCreateDialog extends simplePlugin
return $str;
}
function save ()
function save (): array
{
$this->parent->createSnapshot($this->object_dn, $this->description);
}
......@@ -243,25 +243,25 @@ class SnapshotRestoreDialog extends simplePlugin
protected $snapDn;
protected $snapAction;
static function plInfo()
static function plInfo (): array
{
return array(
'plShortName' => 'SnapshotRestoreDialog',
);
}
static function getAttributesInfo ()
static function getAttributesInfo (): array
{
return array(
'main' => array(
'name' => _('Restoring snapshots'),
'class' => array('fullwidth'),
'attrs' => array(
new DisplayAttribute (
new DisplayAttribute(
_('Object'), _('DN of the object you are creating a snapshot of'),
'object_dn', FALSE
),
new SnapshotsAttribute (
new SnapshotsAttribute(
_('Snapshots'), _('Existing snapshots for this object'),
'snapshots', FALSE,
array(),
......@@ -295,7 +295,7 @@ class SnapshotRestoreDialog extends simplePlugin
}
}
function execute ()
function execute (): string
{
global $ui;
if ($this->dialog == 'delete') {
......@@ -349,7 +349,7 @@ class SnapshotRestoreDialog extends simplePlugin
return $str;
}
function attrIsWriteable($attr)
function attrIsWriteable($attr): bool
{
global $ui;
......@@ -375,7 +375,7 @@ class SnapshotRestoreDialog extends simplePlugin
$this->snapDn = $dn;
}
function save_object()
function save_object ()
{
if ($this->dialog == 'delete') {
if (isset($_POST['delete_confirmed'])) {
......@@ -403,7 +403,7 @@ class SnapshotRestoreDialog extends simplePlugin
$this->updateList();
}
function save ()
function save (): array
{
}
}
......
......@@ -29,7 +29,7 @@
*/
class acl
{
static function plInfo()
static function plInfo ()
{
return array(
'plShortName' => _('ACL'),
......
......@@ -37,7 +37,7 @@ class template
static protected $uiSpecialAttributes = array('dn','cn','uid','sn','givenName');
static function plInfo()
static function plInfo ()
{
return array(
'plShortName' => _('Template'),
......
......@@ -26,7 +26,7 @@ class FilterElement
{
protected $parent;
public function __construct(managementFilter $parent)
public function __construct (managementFilter $parent)
{
$this->parent = $parent;
}
......
......@@ -32,14 +32,14 @@ class ManagementColumnAttribute extends CompositeAttribute
*/
class ManagementConfigurationDialog extends simplePlugin
{
static function plInfo ()
static function plInfo (): array
{
return array(
'plShortName' => 'ManagementConfigurationDialog',
);
}
static function getAttributesInfo ()
static function getAttributesInfo (): array
{
global $class_mapping;
......@@ -57,8 +57,8 @@ class ManagementConfigurationDialog extends simplePlugin
'class' => array('fullwidth'),
'name' => _('Management configuration'),
'attrs' => array(
new OrderedArrayAttribute (
new ManagementColumnAttribute (
new OrderedArrayAttribute(
new ManagementColumnAttribute(
_('Columns'),
_('Columns displayed for this management list'),
'managementColumns',
......@@ -120,7 +120,7 @@ class ManagementConfigurationDialog extends simplePlugin
$this->attributesAccess['managementColumns']->setValue($value);
}
function attrIsWriteable($attr)
function attrIsWriteable($attr): bool
{
global $config, $ui;
......@@ -134,7 +134,7 @@ class ManagementConfigurationDialog extends simplePlugin
}
}
function execute ()
function execute (): string
{
global $config, $ui;
......@@ -151,7 +151,7 @@ class ManagementConfigurationDialog extends simplePlugin
return $str;
}
function save ()
function save (): array
{
global $config;
$columnInfos = array();
......
......@@ -81,7 +81,7 @@ class management
// Whether to display a header or not.
protected $skipHeader = FALSE;
function __construct($objectTypes = FALSE)
function __construct ($objectTypes = FALSE)
{
global $config, $class_mapping;
......@@ -418,7 +418,7 @@ class management
* \brief Execute this plugin
* Handle actions/events, locking, snapshots, dialogs, tabs,...
*/
function execute()
function execute (): string
{
// Ensure that html posts and gets are kept even if we see a 'Entry islocked' dialog.
$vars = array('/^act$/','/^listing/','/^PID$/');
......@@ -433,7 +433,7 @@ class management
// Handle actions (POSTs and GETs)
$action = $this->detectPostActions();
if (!empty($action['action'])) {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $action, 'Action');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $action, 'Action');
try {
$str = $this->handleAction($action);
if ($str) {
......@@ -643,7 +643,7 @@ class management
return;
} else {
if (!$cancel) {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDn, 'Template applied!');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDn, 'Template applied!');
}
del_lock($this->currentDn);
if (empty($this->currentDns)) {
......@@ -686,7 +686,7 @@ class management
// Open object
$this->openTabObject(objects::create($type), $this->listing->getBase());
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDn, 'Create entry initiated');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDn, 'Create entry initiated');
}
function newEntryTemplate(array $action)
......@@ -806,7 +806,7 @@ class management
// Open object
$this->openTabObject(objects::open($this->currentDn, $entry->getTemplatedType()), $this->currentDn);
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDn, 'Edit entry initiated');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDn, 'Edit entry initiated');
if (isset($action['subaction'])
&& ($this->handleSubAction($action) === FALSE)) {
trigger_error('Was not able to handle subaction: '.$action['subaction']);
......@@ -846,7 +846,7 @@ class management
msg_dialog::displayChecks($msgs);
return;
} else {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDns, 'Entry saved');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDns, 'Entry saved');
$this->remove_lock();
$this->closeDialogs();
}
......@@ -858,7 +858,7 @@ class management
return;
} else {
$this->dialogObject->save();
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDns, 'Dialog saved');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDns, 'Dialog saved');
$this->remove_lock();
$this->closeDialogs();
}
......@@ -876,7 +876,7 @@ class management
if (count($msgs)) {
msg_dialog::displayChecks($msgs);
} else {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDns, 'Modifications applied');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDns, 'Modifications applied');
$this->tabObject->re_init();
/* Avoid applying the POST a second time */
$_POST = array();
......@@ -893,7 +893,7 @@ class management
$disallowed = array();
$this->currentDns = array();
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $action['targets'], 'Entry deletion requested');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $action['targets'], 'Entry deletion requested');
// Check permissons for each target
foreach ($action['targets'] as $dn) {
......@@ -957,7 +957,7 @@ class management
function removeConfirmed(array $action)
{
global $ui;
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDns, 'Entry deletion confirmed');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDns, 'Entry deletion confirmed');
foreach ($this->currentDns as $dn) {
$entry = $this->listing->getEntry($dn);
......@@ -1010,11 +1010,11 @@ class management
$entry = $this->listing->getEntry($dn);
if (($action['action'] == 'copy') && $entry->checkAcl('r')) {
$this->cpHandler->add_to_queue($dn, 'copy', $entry->getTemplatedType());
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'Entry copied!');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'Entry copied!');
}
if (($action['action'] == 'cut') && $entry->checkAcl('rd')) {
$this->cpHandler->add_to_queue($dn, 'cut', $entry->getTemplatedType());
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'Entry cut!');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'Entry cut!');
}
}
}
......@@ -1047,7 +1047,7 @@ class management
function createSnapshotDialog(array $action)
{
global $config, $ui;
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $action['targets'], 'Snaptshot creation initiated!');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $action['targets'], 'Snaptshot creation initiated!');
$this->currentDn = array_pop($action['targets']);
if (empty($this->currentDn)) {
......@@ -1085,7 +1085,7 @@ class management
}
if ($ui->allow_snapshot_restore($this->currentDn, $aclCategory, empty($action['targets']))) {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDn, 'Snaptshot restoring initiated!');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->currentDn, 'Snaptshot restoring initiated!');
$this->dialogObject = new SnapshotRestoreDialog($this->currentDn, $this, empty($action['targets']), $aclCategory);
} else {
msg_dialog::display(_('Permission'), sprintf(_('You are not allowed to restore a snapshot for %s.'), $this->currentDn),
......@@ -1174,7 +1174,7 @@ class management
}
if (!empty($dn) && $ui->allow_snapshot_create($dn, $this->dialogObject->aclCategory)) {
$this->snapHandler->createSnapshot($dn, $description);
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'Snaptshot created!');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'Snaptshot created!');
} else {
msg_dialog::display(_('Permission'), sprintf(_('You are not allowed to restore a snapshot for %s.'), $dn),
ERROR_DIALOG);
......@@ -1191,7 +1191,7 @@ class management
global $ui;
if (!empty($dn) && $ui->allow_snapshot_restore($dn, $this->dialogObject->aclCategory, $this->dialogObject->global)) {
$this->snapHandler->restoreSnapshot($dn);
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'Snaptshot restored');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'Snaptshot restored');
$this->closeDialogs();
} else {
msg_dialog::display(_('Permission'), sprintf(_('You are not allowed to restore a snapshot for %s.'), $dn),
......@@ -1209,7 +1209,7 @@ class management
global $ui;
if (!empty($dn) && $ui->allow_snapshot_delete($dn, $this->dialogObject->aclCategory)) {
$this->snapHandler->removeSnapshot($dn);
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'Snaptshot deleted');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'Snaptshot deleted');
} else {
msg_dialog::display(_('Permission'), sprintf(_('You are not allowed to delete a snapshot for %s.'), $dn),
ERROR_DIALOG);
......
......@@ -202,21 +202,21 @@ class TimeHisAttribute extends CompositeAttribute
{
protected $convert;
function __construct($label, $description, $ldapName, $required, $convert = TRUE, $acl = '')
function __construct ($label, $description, $ldapName, $required, $convert = TRUE, $acl = '')
{
$this->convert = $convert;
$attributes = array(
new IntAttribute (
new IntAttribute(
'', _('Hours'),
$ldapName.'_hours', TRUE,
0, 23, 1
),
new IntAttribute (
new IntAttribute(
':', _('Minutes'),
$ldapName.'_minutes', TRUE,
0, 59, 0
),
new IntAttribute (
new IntAttribute(
':', _('Seconds'),
$ldapName.'_seconds', TRUE,
0, 59, 0
......@@ -276,16 +276,16 @@ class TimeHisAttribute extends CompositeAttribute
*/
class TimeHiAttribute extends TimeHisAttribute
{
function __construct($label, $description, $ldapName, $required, $convert = TRUE, $acl = '')
function __construct ($label, $description, $ldapName, $required, $convert = TRUE, $acl = '')
{
$this->convert = $convert;
$attributes = array(
new IntAttribute (
new IntAttribute(
'', _('Hours'),
$ldapName.'_hours', TRUE,
0, 23, 1
),
new IntAttribute (
new IntAttribute(
':', _('Minutes'),
$ldapName.'_minutes', TRUE,
0, 59, 0
......@@ -301,7 +301,7 @@ class TimeHiAttribute extends TimeHisAttribute
*/
class DateTimeAttribute extends CompositeAttribute
{
function __construct($label, $description, $ldapName, $required, $acl = '')
function __construct ($label, $description, $ldapName, $required, $acl = '')
{
$attributes = array(
new DateAttribute(
......
......@@ -543,7 +543,7 @@ class OrderedArrayAttribute extends SetAttribute
return array ($img, $nbicons);
}
protected function getAttributeArrayValue($key, $value)
protected function getAttributeArrayValue ($key, $value)
{
$this->attribute->setValue($value);
return $this->attribute->getArrayValue();
......
......@@ -32,7 +32,7 @@ class multiPlugin extends simplePlugin
var $tabClass = '';
static function getAttributesInfo ()
static function getAttributesInfo (): array
{
return array();
}
......@@ -60,7 +60,7 @@ class multiPlugin extends simplePlugin
}
}
function execute()
function execute (): string
{
$display = "";
......@@ -102,7 +102,7 @@ class multiPlugin extends simplePlugin
/* Save data to object */
function save_object()
function save_object ()
{
foreach ($this->plugin as &$plug) {
$plug->save_object();
......@@ -110,7 +110,7 @@ class multiPlugin extends simplePlugin
unset($plug);
}
function check()
function check (): array
{
$message = parent::check();
......@@ -125,7 +125,7 @@ class multiPlugin extends simplePlugin
return $message;
}
function set_acl_category($cat)
function set_acl_category ($cat)
{
parent::set_acl_category($cat);
foreach ($this->plugin as &$plug) {
......@@ -134,7 +134,7 @@ class multiPlugin extends simplePlugin
unset($plug);
}
function set_acl_base($base)
function set_acl_base ($base)
{
parent::set_acl_base($base);
foreach ($this->plugin as &$plug) {
......@@ -153,7 +153,7 @@ class multiPlugin extends simplePlugin
}
/* Save to LDAP */
function save()
function save (): array
{
$errors = array();
/* Save objects */
......@@ -172,7 +172,7 @@ class multiPlugin extends simplePlugin
return $errors;
}
function remove($fulldelete = FALSE)
function remove (bool $fulldelete = FALSE): array
{
$errors = array();
/* Remove objects */
......@@ -187,7 +187,7 @@ class multiPlugin extends simplePlugin
return $errors;
}
function adapt_from_template($attrs, $skip = array())
function adapt_from_template (array $attrs, array $skip = array())
{
/* Adapt objects */
foreach ($this->plugin as &$plug) {
......@@ -197,7 +197,7 @@ class multiPlugin extends simplePlugin
unset($plug);
}
function resetCopyInfos()
function resetCopyInfos ()
{
$this->dn = 'new';
foreach ($this->plugin as &$plug) {
......
......@@ -251,7 +251,7 @@ class simplePlugin
/* Set the template flag according to the existence of objectClass fdTemplate */
if (isset($this->attrs['objectClass']) && in_array_ics('fdTemplate', $this->attrs['objectClass'])) {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, 'found', 'Template check');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, 'found', 'Template check');
$this->setTemplate(TRUE);
$this->templateLoadAttrs($this->attrs);
}
......@@ -259,7 +259,7 @@ class simplePlugin
/* Is Account? */
if ($this->is_this_account($this->attrs)) {
$this->is_account = TRUE;
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, get_class($this), 'Tab active');
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, get_class($this), 'Tab active');
}
}
......@@ -302,7 +302,7 @@ class simplePlugin
}
}
protected function loadAttributes()
protected function loadAttributes ()
{
// We load attributes values
// First the one flagged as preInit
......@@ -325,7 +325,7 @@ class simplePlugin
unset($sectionInfo);
}
function is_this_account($attrs)
function is_this_account ($attrs)
{
$result = static::isAccount($attrs);
if ($result === NULL) {
......@@ -337,7 +337,7 @@ class simplePlugin
if (preg_match('/^top$/i', $obj)) {
continue;
}
if (!isset($attrs['objectClass']) || !in_array_ics ($obj, $attrs['objectClass'])) {
if (!isset($attrs['objectClass']) || !in_array_ics($obj, $attrs['objectClass'])) {
$found = FALSE;
break;
}
......@@ -381,7 +381,7 @@ class simplePlugin
}
}
protected function templateLoadAttrs(array $template_attrs)
protected function templateLoadAttrs (array $template_attrs)
{
if ($this->mainTab) {
$this->_template_cn = $template_attrs['cn'][0];
......@@ -389,7 +389,7 @@ class simplePlugin
$this->attrs = templateHandling::fieldsFromLDAP($template_attrs);
}
protected function templateSaveAttrs()
protected function templateSaveAttrs ()
{
global $config;
$ldap = $config->get_ldap_link();
......@@ -424,7 +424,7 @@ class simplePlugin
* It calls the getValue method on the concerned attribute
* It also adds the $plugin->attribtues syntax to get attributes list
*/
public function __get($name)
public function __get ($name)
{
if ($name == 'attributes') {
$plugin = $this;
......@@ -446,7 +446,7 @@ class simplePlugin
It calls the setValue method on the concerned attribute
*/
public function __set($name, $value)
public function __set ($name, $value)
{
if ($name == 'attributes') {
trigger_error('Tried to set obsolete attribute "attributes" (it is now dynamic)');
......@@ -462,7 +462,7 @@ class simplePlugin
It returns FALSE if the attribute has an empty value.
*/
public function __isset($name)
public function __isset ($name)
{
if ($name == 'attributes') {
return TRUE;
......@@ -472,7 +472,7 @@ class simplePlugin
/*! \brief This function returns the dn this object should have
*/
public function compute_dn(): string
public function compute_dn (): string
{
global $config;
if (!$this->mainTab) {
......@@ -539,7 +539,7 @@ class simplePlugin
*
* \return array [dn] => "..name" // All deps. we are allowed to act on.
*/
function get_allowed_bases(): array
function get_allowed_bases (): array
{
global $config;
$deps = array();
...