Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# OS
.DS_Store
Thumbs.db

# Editor
.idea/
.vscode/
*.swp
*~

# Local / temp
*.log
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Behaviors plugin for GLPI — GLPI 11 compatible

This is a **GLPI 11–compatible** version of the [Behaviors](https://github.com/yllen/behaviors) plugin.

- **Original authors:** Remi Collet, Nelly Mahu-Lasson
- **GLPI 11 port:** Lokmane BENAZIZA
- **Version:** 2.8.0
- **License:** AGPLv3+

## Compatibility

- **GLPI:** 10.0.5 – 11.x
- **PHP:** same as your GLPI version

## Installation

1. [Download](https://github.com/loulouontop/behaviors-GLPI-11/releases) the latest release (or clone this repo).
2. Place the **contents** of this repo (the plugin files) inside a folder named `behaviors` in your GLPI directory:
- **Plugins:** `glpi/plugins/behaviors`
- **Marketplace:** `glpi/marketplace/behaviors`
3. In GLPI go to **Setup → Plugins**, find **Behaviours** and click **Install**, then **Enable**.

## Changes in this fork (GLPI 11)

- Version requirement updated for GLPI 11.
- Method return types added for CommonGLPI/CommonDBTM compatibility.
- Raw SQL removed: table creation and updates use `Migration::addPreQuery()` / `addPostQuery()`.
- Database queries use the query builder (`['FROM' => ..., 'WHERE' => ...]`).
- Removed `addslashes` / `Toolbox::addslashes_deep` (handled by GLPI 11).
- Safe handling of `asset_types` and optional `check_prerequisites`.
- Front scripts adjusted for GLPI 11 (no `includes.php`, error handling).

## Original plugin

Based on [yllen/behaviors](https://github.com/yllen/behaviors).
For the official plugin (GLPI 10.x), see the [original repository](https://github.com/yllen/behaviors).
14 changes: 11 additions & 3 deletions behaviors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,31 @@
]]></en>
</long>
</description>
<homepage>https://github.com/yllen/behaviors</homepage>
<download>https://github.com/yllen/behaviors/releases</download>
<homepage>https://github.com/loulouontop/behaviors-GLPI-11</homepage>
<download>https://github.com/loulouontop/behaviors-GLPI-11/releases</download>
<authors>
<author>Lokmane BENAZIZA</author>
<author>Remi Collet</author>
<author>Nelly Mahu-Lasson</author>
</authors>
<versions>
<version>
<num>2.8.0</num>
<compatibility>~10.0.5</compatibility>
<compatibility>~11.0</compatibility>
<download_url>https://github.com/loulouontop/behaviors-GLPI-11/releases/download/v2.8.0/glpi-behaviors-2.8.0.tar.gz</download_url>
</version>
<version>
<num>2.7.3</num>
<compatibility>~10.0.5</compatibility>
<compatibility>~11.0</compatibility>
<download_url>https://github.com/yllen/behaviors/releases/download/v2.7.3/glpi-behaviors-2.7.3.tar.gz</download_url>
</version>
<version>
<num>2.7.2</num>
<compatibility>~10.0.3</compatibility>
<download_url>https://github.com/yllen/behaviors/releases/download/v2.7.2/glpi-behaviors-2.7.2.tar.gz</download_url>
</version>
</version>
<version>
<num>2.7.1</num>
<compatibility>10.0.0</compatibility>
Expand Down
5 changes: 3 additions & 2 deletions front/common.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
--------------------------------------------------------------------------
*/

include ("../../../inc/includes.php");
// GLPI 11: includes.php no longer required

$config = new PluginBehaviorsCommon();
if (isset($_POST["_clone"])) {
PluginBehaviorsCommon::cloneItem($_POST);

Html::back();
}
Html::displayErrorAndDie('Lost!');
Session::addMessageAfterRedirect(__('Invalid request', 'behaviors'), true, ERROR);
Html::back();
4 changes: 2 additions & 2 deletions front/config.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
--------------------------------------------------------------------------
*/

include ("../../../inc/includes.php");
// GLPI 11: includes.php no longer required (handled by single entry point)

// No autoload when plugin is not activated
require_once('../inc/config.class.php');
Expand All @@ -44,5 +44,5 @@

Html::back();
}
Html::redirect($CFG_GLPI["root_doc"]."/front/config.form.php?forcetab=".
Html::redirect($CFG_GLPI["root_doc"] . "/front/config.form.php?forcetab=" .
urlencode('PluginBehaviorsConfig$1'));
35 changes: 24 additions & 11 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,36 @@


function plugin_behaviors_install() {

$migration = new Migration(270);

// No autoload when plugin is not activated
require_once('inc/config.class.php');
PluginBehaviorsConfig::install($migration);

$migration->executeMigration();

return true;
try {
$migration = new Migration(270);

// No autoload when plugin is not activated
require_once(__DIR__ . '/inc/config.class.php');
PluginBehaviorsConfig::install($migration);

$migration->executeMigration();

return true;
} catch (Throwable $e) {
if (class_exists('Toolbox') && method_exists('Toolbox', 'logError')) {
Toolbox::logError('Behaviors plugin install failed: ' . $e->getMessage());
}
if (class_exists('Session') && method_exists('Session', 'addMessageAfterRedirect')) {
Session::addMessageAfterRedirect(
'Behaviors plugin install failed: ' . $e->getMessage(),
true,
ERROR
);
}
return false;
}
}


function plugin_behaviors_uninstall() {

// No autoload when plugin is not activated
require 'inc/config.class.php';
require __DIR__ . '/inc/config.class.php';

$migration = new Migration(270);

Expand Down
12 changes: 6 additions & 6 deletions inc/change.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ static function beforeUpdate(Change $change) {

if (isset($change->input['status'])
&& in_array($change->input['status'], array_merge(Change::getSolvedStatusArray(),
Change::getclosedStatusArray()))) {
Change::getClosedStatusArray()))) {

$soluce = $DB->request('glpi_itilsolutions',
['itemtype' => 'Change',
'items_id' => $change->input['id']]);
$soluce = $DB->request(['FROM' => 'glpi_itilsolutions',
'WHERE' => ['itemtype' => 'Change',
'items_id' => $change->input['id']]]);

if ($config->getField('is_changetasktodo')) {
foreach($DB->request('glpi_changetasks',
['changes_id' => $change->getField('id')]) as $task) {
foreach($DB->request(['FROM' => 'glpi_changetasks',
'WHERE' => ['changes_id' => $change->getField('id')]]) as $task) {
if ($task['state'] == 1) {
Session::addMessageAfterRedirect(__("You cannot solve/close a change with task do to",
'behaviors'), true, ERROR);
Expand Down
22 changes: 11 additions & 11 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static function postInit() {
}


function getTabNameForItem(CommonGLPI $item, $withtemplate=0) {
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0): string {

$config = PluginBehaviorsConfig::getInstance();

Expand Down Expand Up @@ -137,7 +137,7 @@ static function showCloneForm(CommonGLPI $item) {
}


static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) {
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0): bool {

if (array_key_exists($item->getType(), self::$clone_types)
&& $item->canUpdate()) {
Expand All @@ -161,7 +161,7 @@ static function cloneItem(Array $param) {
// Read original and prepare clone
$item->check($param['id'], READ);

$input = ToolBox::addslashes_deep($item->fields);
$input = $item->fields;
$input['name'] = $param['name'];
$input['_add'] = 1;
$input['_old_id'] = $input['id'];
Expand Down Expand Up @@ -205,8 +205,8 @@ static function cloneItem(Array $param) {
if ($clone->dohistory) {
$changes[0] = '0';
$changes[1] = '';
$changes[2] = addslashes(sprintf(__('%1$s %2$s'), __('Clone of', 'behaviors'),
$item->getNameID(0, true)));
$changes[2] = sprintf(__('%1$s %2$s'), __('Clone of', 'behaviors'),
$item->getNameID(0, true));
Log::history($clone->getID(), $clone->getType(), $changes, 0,
Log::HISTORY_LOG_SIMPLE_MESSAGE);
}
Expand Down Expand Up @@ -285,8 +285,8 @@ static function checkWarnings($params) {
}

if ($config->getField('is_tickettasktodo')) {
foreach ($DB->request('glpi_tickettasks',
['tickets_id' => $obj->getField('id')]) as $task) {
foreach ($DB->request(['FROM' => 'glpi_tickettasks',
'WHERE' => ['tickets_id' => $obj->getField('id')]]) as $task) {
if ($task['state'] == 1) {
$warnings[] = __("You cannot solve/close a ticket with task do to", 'behaviors');
break;
Expand All @@ -297,8 +297,8 @@ static function checkWarnings($params) {

if ($obj->getType() == 'Problem') {
if ($config->getField('is_problemtasktodo')) {
foreach ($DB->request('glpi_problemtasks',
['problems_id' => $obj->getField('id')]) as $task) {
foreach ($DB->request(['FROM' => 'glpi_problemtasks',
'WHERE' => ['problems_id' => $obj->getField('id')]]) as $task) {
if ($task['state'] == 1) {
$warnings[] = __("You cannot solve/close a problem with task do to", 'behaviors');
break;
Expand All @@ -309,8 +309,8 @@ static function checkWarnings($params) {

if ($obj->getType() == 'Change') {
if ($config->getField('is_changetasktodo')) {
foreach ($DB->request('glpi_changetasks',
['changes_id' => $obj->getField('id')]) as $task) {
foreach ($DB->request(['FROM' => 'glpi_changetasks',
'WHERE' => ['changes_id' => $obj->getField('id')]]) as $task) {
if ($task['state'] == 1) {
$warnings[] = __("You cannot solve/close a change with task do to", 'behaviors');
break;
Expand Down
Loading