Skip to content

Instantly share code, notes, and snippets.

@may-cat
Last active May 18, 2016 22:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save may-cat/d75fa51f5977428ee251 to your computer and use it in GitHub Desktop.
Save may-cat/d75fa51f5977428ee251 to your computer and use it in GitHub Desktop.
Full D7 / bitrix module install index.php
<?php
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
if (class_exists('maycat_somemodule')) {
return;
}
class maycat_somemodule extends CModule
{
public $MODULE_ID = 'maycat.somemodule';
public $MODULE_VERSION = '0.0.1';
public $MODULE_VERSION_DATE = '2014-07-17 16:23:14';
public $MODULE_NAME = 'Сервис SOMEMODULE';
public $MODULE_DESCRIPTION = '';
public $MODULE_GROUP_RIGHTS = 'N';
public $PARTNER_NAME = "May-cat";
public $PARTNER_URI = "http://bitrix.expert";
public function DoInstall()
{
global $APPLICATION,$DB;
// Install DB //
$errors = $DB->RunSQLBatch(__DIR__ . '/db/' . strtolower($DB->type) . '/install.sql');
if ($errors)
{
$APPLICATION->ThrowException(implode('<br>', (array)$errors));
return false;
}
// create agent
\CAgent::AddAgent(
"Maycat\\Somemodule\\General\\Agents::clearSearchCache();",
"maycat.somemodule",
"N",
600,
"",
"Y");
// connect to event handlers
RegisterModuleDependences("sale", "OnSaleBeforeCancelOrder", "maycat.somemodule", "\\Maycat\\Somemodule\\Handlers\\Orders", "onBeforeSaleOrderStatusChange");
// Install files //
$arParams = array();
DeleteDirFiles(__DIR__ . '/admin/', $_SERVER['DOCUMENT_ROOT'] . '/bitrix/admin/');
if (!array_key_exists('savedata', $arParams) || $arParams['savedata'] !== 'Y') {
DeleteDirFilesEx('upload/' . $this->MODULE_ID);
}
// //
RegisterModule($this->MODULE_ID);
return true;
}
public function DoUninstall()
{
global $APPLICATION, $DB;
$arParams = array('savedata' => $_REQUEST['savedata']);
// uninstall db //
if (!array_key_exists('savedata', $arParams) || $arParams['savedata'] !== 'Y') {
$errors = $DB->RunSQLBatch(__DIR__ . '/db/' . strtolower($DB->type) . '/uninstall.sql');
if ($errors) {
$APPLICATION->ThrowException(implode('<br>', (array)$errors));
return false;
}
}
// uninstall files //
DeleteDirFiles(__DIR__ . '/admin/', $_SERVER['DOCUMENT_ROOT'] . '/bitrix/admin/');
if (!array_key_exists('savedata', $arParams) || $arParams['savedata'] !== 'Y') {
DeleteDirFilesEx('upload/' . $this->MODULE_ID);
}
// @todo: delete agent
// disconnect event handlers
UnRegisterModuleDependences("sale", "OnSaleBeforeCancelOrder", "maycat.somemodule", "\\Maycat\\Somemodule\\Handlers\\Orders", "onBeforeSaleOrderStatusChange");
// //
UnRegisterModule($this->MODULE_ID);
return true;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment