In order that the module can be installed optionally, created a module installation file. This is the file modules/module_name/module_name.install.php. It must be defined the class Module_name_install
that inherits the class Install
.
This file is used during installation DIAFAN.CMS, when installing / removing the module from the administrative part, if you restore a database from the administrative part.
var is_core = false – module is piece of core.
Example:
// modules/site/site.install.php
public $is_core = true;
var module – название текущиего модуля.
The property is filled in automatically when initiating the installation of the module and contains the name of the module.Example:
// modules/users/users.install.php
public $title = "Users";
var install_modules – установленные/устанавливаемые модули.
It contains an array of all defined or established in the current module. Used for example for filling examples in modules that are connected to other modules.var langs – идентификаторы языков сайта.
It contains an array of site identifiers language of the module installation time.var tables = array() – tables in the database.
Example:
public $tables = array(
array(
"name" => "table_name",
// table fields
"fields" => array(
array(
// example: id
"name" => "field_name",
// example: INT(11) UNSIGNED NOT NULL AUTO_INCREMENT
"type" => "field description",
// field translated into other languages (true|false)
"multilang" => true,
// comment visible from database manager
"comment" => "comment to field",
),
...
),
// table keys
"keys" => array(
// example: PRIMARY KEY (id) или KEY site_id (`site_id`)
"key_description",
...
),
// comment visible from database manager
"comment" => "comment to table",
),
...
);
All modules of the table must begin with a module name. For example, the module table "News" – {news}, {news_category} and so on..
var modules = array() – record in the table {modules}.
When installing the module, be sure to do a record in the table {modules} to the system identified as the module installed.
Example:
public $modules = array(
array(
// example: cart
"name" => "embedded module name",
// it is the administrative part (true|false)
"admin" => true,
// it is the public part (true|false)
"site" => true,
// can be attached to the site page (true|false)
"site_page" => true,
// example: Cart
// may be omitted if the entry name is the name of the main module
"title" => "module_title",
),
);
var admin = array() – menu of the control panel.
Example:
public $admin = array(
array(
"name" => "name",
"rewrite" => "Semantic URL",
"group_id" => "group_id",
"sort" => "sequence_number_for_sorting",
// display in menu (true|false)
"act" => true,
"docs" => "link to manual",
// subpages
"children" => array(
array(
"name" => "name",
"rewrite" => "Semantic URL",
"sort" => "sequence_number_for_sorting",
// display in menu (true|false)
"act" => true,
),
)
),
...
);
var site = array() – site pages.
Example:
public $site = array(
array(
// example: Onine shop, Каталог товаров
"name" => array("english_name", "russian_name"),
// example: 15 – optional
"sort" => "sequence_number_for_sorting",
// example: shop – optional
"module_name" => "attached_module",
// example: online-shop
"rewrite" => "semantic_url",
// example: sitemap.php – optional
"theme" => "page template",
// skip to the sitemap (true|false)
"map_no_show" => true,
// not index (true|false)
"noindex" => true,
// does not participate in the SERP (true|false)
"search_no_show" => true,
// link in menu – optional
"menu" => "menu ID",
),
...
);
var config = array() – settings.
Example:
public $config = array(
array(
"name" => "name",
// default current module
"module_name" => "module_name",
// if the value is translated into different languages you can set as an array
"value" => "value",
),
);
var sql = array() – предустановленные данные.
To be filled in if installation of the module you want to insert the initial or required data in the module database tables.
Example:
public $sql = array(
"table_name" => array(
array(
"поле" => "value",
"поле2" => "second_value",
),
array(
"поле" => "value",
"поле2" => "second_value",
),
),
"second_table_name" => array(
...
),
...
);
var demo = array() – demo data.
The format is the same as the previous property. But these are only filled in if the option is checked "Fill the site with examples from the demo version".void start (boolean $demo) – Устанавливаем модуль.
Example:
// installing module "News"
include_once(ABSOLUTE_PATH.'modules/news/news.install.php');
$module = News_install($this->diafan);
$module->start(true);
void action () – Executes the actions during installation module.
The function can be determined if you need to install to commit acts which does not satisfy the standard in the logic unit.
For example, in the module "Site languages" additional language added if the option marked "Create two language versions of the site".
Example:
protected function action()
{
if (count($this->langs) > 1)
{
$this->sql["languages"][] =
array(
"id" => 2,
"name" => 'eng',
"shortname" => 'eng',
);
}
}
void action_post () – Executes the actions during installation module после основной установки.
The function can be determined if you want to perform a set of actions after the installation of all modules.
For example, in the module "Search" to index the content of all the modules.
Example:
public function action_post()
{
$this->diafan->_search->index_all();
}
void tables ([array $array = array()]) – Добавляет таблицы.
void modules ([array $array = array()]) – Добавляет запись в таблицу {modules}.
void admin ([array $array = array()], [integer $parent_id = 0], [array $parent = array()]) – Добавляет записи о модуле в таблицу {admin} - страницы админки.
void site ([array $rows = array()]) – Добавляет страницы сайта.
void config ([array $array = array()]) – Добавляет запись в таблицу {config}.
void sql ([array $array = array()]) – Выполняет SQL-запросы.
void demo () – Установка demo-данных.
void uninstall () – Удаляет модуль.
void uninstall_action () – Executes the actions during installation module.
The function can be determined if you want to perform a set of actions after the removal of the module.
For example, in the module "Online shop" must be removed to create page "Order is processed", to which the module is not connected.
Example:
protected function uninstall_action()
{
DB::query("DELETE FROM {rewrite} WHERE rewrite='shop/cart/done'");
DB::query("DELETE FROM {site} WHERE [name]='Order is processed'");
}