Skip to content

Commit e301acf

Browse files
Add more upgrade instructions for GLPI 11.0 (#157)
* Add more upgrade instructions for GLPI 11.0 * Apply suggestions from code review Co-authored-by: Curtis Conard <[email protected]> --------- Co-authored-by: Curtis Conard <[email protected]>
1 parent bf79a83 commit e301acf

File tree

1 file changed

+73
-3
lines changed

1 file changed

+73
-3
lines changed

source/upgradeguides/glpi-11.0.rst

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,83 @@ If you were using the second syntax, you will need to replace as follows:
7474
7575
Using raw SQL queries must be replaced with query builder call, among other to prevent syntax issues, and SQL injections; please refer to :doc:devapi/database/dbiterator.
7676

77-
Changes related to URLs routing
78-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
77+
Changes related to web requests handling
78+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79+
80+
In GLPI 11.0, all the web requests are now handled by a unique entry point, the ``/public/index.php`` script.
81+
This allowed us to centralize a large number of things, including GLPI's initialization mechanics and error management.
82+
83+
Removal of the ``/inc/includes.php`` script
84+
+++++++++++++++++++++++++++++++++++++++++++
85+
86+
All the logic that was executed by the inclusion of the ``/inc/includes.php`` script is now made automatically.
87+
Therefore, it is no longer necessary to include it, even if it is still present to ease the migration to GLPI 11.0.
88+
89+
.. code-block:: diff
90+
91+
- include("../../../inc/includes.php");
92+
93+
Legacy scripts access policy
94+
++++++++++++++++++++++++++++
95+
96+
By default, the access to any PHP script will be allowed only to authenticated users.
97+
If you need to change this default policy for some of your PHP scripts, you will need to do this in your plugin ``init`` function,
98+
using the ``Glpi\Http\Firewall::addPluginFallbackStrategy()`` method.
99+
100+
.. code-block:: php
101+
102+
<?php
103+
104+
use Glpi\Http\Firewall;
105+
106+
function plugin_init_myplugin() {
107+
Firewall::addPluginFallbackStrategy('myplugin', '#^/front/api.php/#', Firewall::STRATEGY_NO_CHECK);
108+
Firewall::addPluginFallbackStrategy('myplugin', '#^/front/dashboard.php$#', Firewall::STRATEGY_CENTRAL_ACCESS);
109+
}
110+
111+
The following strategies are available:
112+
113+
* ``Firewall::STRATEGY_NO_CHECK``: no check is done, anyone can access your script, even unauthenticated users;
114+
* ``Firewall::STRATEGY_AUTHENTICATED``: only authenticated users can access your script, it is the default strategy for all PHP scripts;
115+
* ``Firewall::STRATEGY_CENTRAL_ACCESS``: only users with access to the standard interface can access your script;
116+
* ``Firewall::STRATEGY_HELPDESK_ACCESS``: only users with access to the simplified interface can access your script;
117+
* ``Firewall::STRATEGY_FAQ_ACCESS``: only users with a read access to the FAQ will be allowed to access your script, unless the FAQ is configured to be public.
118+
119+
Handling of response codes and early script exit
120+
++++++++++++++++++++++++++++++++++++++++++++++++
121+
122+
Usage of the ``exit()``/``die()`` language construct is now discouraged as it prevents the execution of routines that might take place after the request has been executed.
123+
Also, due to a PHP bug (see https://bugs.php.net/bug.php?id=81451), the usage of the ``http_response_code()`` function will produce unexpected results, depending on the server environment.
124+
125+
In the case they were used to exit the script early due to an error, you can replace them by throwing an exception.
126+
Any exception thrown will now be caught correctly and forwarded to the error handler.
127+
If this exception is thrown during the execution of a web request, the GLPI error page will be shown, unless this exception is handled by a specific routine.
128+
129+
.. code-block:: diff
130+
131+
if ($item->getFromDB($_GET['id']) === false) {
132+
- http_response_code(404);
133+
- exit();
134+
+ throw new \Glpi\Exception\Http\NotFoundHttpException();
135+
}
136+
137+
In case the ``exit()``/``die()`` language construct was used to just ignore the following line of code in the script, you can replace it with a ``return`` instruction.
138+
139+
.. code-block:: diff
140+
141+
if ($action === 'foo') {
142+
// specific action
143+
echo "foo action executed";
144+
- exit();
145+
+ return;
146+
}
147+
148+
MypluginItem::displayFullPageForItem($_GET['id']);
79149
80150
Crafting plugins URLs
81151
+++++++++++++++++++++
82152

83-
In GLPI 11.0, we changed the way to handle URLs to plugin resources so that they no longer need to reflect the location of the plugin on the file system.
153+
We changed the way to handle URLs to plugin resources so that they no longer need to reflect the location of the plugin on the file system.
84154
For instance, the same URL could be used to access a plugin file whether it was installed manually in the ``/plugins`` directory or via the marketplace.
85155

86156
To maintain backwards compatibility with previous behavior, we will continue to support URLs using the ``/marketplace`` path prefix.

0 commit comments

Comments
 (0)