Date: Thu, 28 Mar 2024 17:26:35 +0000 (UTC) Message-ID: <631108383.29.1711646795052@69847700fc8c> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_28_2113643709.1711646795052" ------=_Part_28_2113643709.1711646795052 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Currently, many of our modules have no .install file, yet they set Drupa= l system variables that would get left behind in the database if the module= were disabled/removed. Adding this function to an existing .install file, = or creating a blank .install file with just this function will remedy this.= If the .install file already has a hook_uninstall() function, check the co= de to make sure it does something similar to this funciton to clean up its = variables.
This works for version 5.x and 6.x modules.
<?ph= p function modulename_uninstall() { // remove module system variables $module_name =3D 'modulename'; $vars =3D db_query("select * from {variable} where name like '" . $module= _name . "%'"); while ($var =3D db_fetch_object($vars)) { variable_del($var->name); } }
<?ph= p function newmodulename_install() { // rename module system variables $oldname =3D 'modulename'; $newname =3D 'newmodulename'; =20 $vars =3D db_query("select * from {variable} where name like '" . $oldnam= e . "%'"); while ($var =3D db_fetch_object($vars)) { $newvar =3D str_replace($oldname,$newname,$var->name); variable_set($newvar, variable_get($var->name, NULL)); variable_del($var->name); } }