This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Конструкторы миграций * Конструктор свойств * Конструктор списков * Конструктор HL * Update README.md * Update Migrator.php
- Loading branch information
Showing
17 changed files
with
2,027 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
|
||
namespace Arrilot\BitrixMigrations\Constructors; | ||
|
||
|
||
class Constructor | ||
{ | ||
const OBJ_USER = 'USER'; // для пользователя | ||
const OBJ_BLOG_BLOG = 'BLOG_BLOG'; // для блога | ||
const OBJ_BLOG_POST = 'BLOG_POST'; // для сообщения в блоге | ||
const OBJ_BLOG_COMMENT = 'BLOG_COMMENT'; // для комментария сообщения | ||
const OBJ_TASKS_TASK = 'TASKS_TASK'; // для задач | ||
const OBJ_CALENDAR_EVENT = 'CALENDAR_EVENT'; // для событий календаря | ||
const OBJ_LEARN_ATTEMPT = 'LEARN_ATTEMPT'; // для попыток теста | ||
const OBJ_SONET_GROUP = 'SONET_GROUP'; // для групп соцсети | ||
const OBJ_WEBDAV = 'WEBDAV'; // для библиотек документов | ||
const OBJ_FORUM_MESSAGE = 'FORUM_MESSAGE'; // для сообщений форума | ||
|
||
/** | ||
* для highload-блока с ID=N | ||
* @param $id | ||
* @return string | ||
*/ | ||
public static function objHLBlock($id) | ||
{ | ||
return "HLBLOCK_{$id}"; | ||
} | ||
|
||
/** | ||
* для секций инфоблока с ID = N | ||
* @param $id | ||
* @return string | ||
*/ | ||
public static function objIBlockSection($id) | ||
{ | ||
return "IBLOCK_{$id}_SECTION"; | ||
} | ||
|
||
/** | ||
* Для инфоблока с ID = N | ||
* @param $id | ||
* @return string | ||
*/ | ||
public static function objIBlock($id) | ||
{ | ||
return "IBLOCK_{$id}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
|
||
namespace Arrilot\BitrixMigrations\Constructors; | ||
|
||
|
||
trait FieldConstructor | ||
{ | ||
/** @var array */ | ||
public $fields = []; | ||
|
||
public static $defaultFields = []; | ||
|
||
/** | ||
* Получить итоговые настройки полей | ||
*/ | ||
public function getFieldsWithDefault() | ||
{ | ||
return array_merge((array)static::$defaultFields[get_called_class()], $this->fields); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
|
||
namespace Arrilot\BitrixMigrations\Constructors; | ||
|
||
|
||
use Arrilot\BitrixMigrations\Helpers; | ||
use Arrilot\BitrixMigrations\Logger; | ||
use Bitrix\Highloadblock\HighloadBlockLangTable; | ||
use Bitrix\Highloadblock\HighloadBlockTable; | ||
|
||
class HighloadBlock | ||
{ | ||
use FieldConstructor; | ||
|
||
public $lang; | ||
|
||
/** | ||
* Добавить HL | ||
* @throws \Exception | ||
*/ | ||
public function add() | ||
{ | ||
$result = HighloadBlockTable::add($this->getFieldsWithDefault()); | ||
|
||
if (!$result->isSuccess()) { | ||
throw new \Exception(join(', ', $result->getErrorMessages())); | ||
} | ||
|
||
foreach ($this->lang as $lid => $name) { | ||
HighloadBlockLangTable::add([ | ||
"ID" => $result->getId(), | ||
"LID" => $lid, | ||
"NAME" => $name | ||
]); | ||
} | ||
|
||
Logger::log("Добавлен HL {$this->fields['NAME']}", Logger::COLOR_GREEN); | ||
|
||
return $result->getId(); | ||
} | ||
|
||
/** | ||
* Обновить HL | ||
* @param $table_name | ||
* @throws \Exception | ||
*/ | ||
public function update($table_name) | ||
{ | ||
$id = Helpers::getHlId($table_name); | ||
$result = HighloadBlockTable::update($id, $this->fields); | ||
|
||
if (!$result->isSuccess()) { | ||
throw new \Exception(join(', ', $result->getErrorMessages())); | ||
} | ||
|
||
Logger::log("Обновлен HL {$table_name}", Logger::COLOR_GREEN); | ||
} | ||
|
||
/** | ||
* Удалить HL | ||
* @param $table_name | ||
* @throws \Exception | ||
*/ | ||
public static function delete($table_name) | ||
{ | ||
$id = Helpers::getHlId($table_name); | ||
$result = HighloadBlockTable::delete($id); | ||
|
||
if (!$result->isSuccess()) { | ||
throw new \Exception(join(', ', $result->getErrorMessages())); | ||
} | ||
|
||
Logger::log("Удален HL {$table_name}", Logger::COLOR_GREEN); | ||
} | ||
|
||
/** | ||
* Установить настройки для добавления HL по умолчанию | ||
* @param string $name Название highload-блока | ||
* @param string $table_name Название таблицы с элементами highload-блока. | ||
* @return $this | ||
*/ | ||
public function constructDefault($name, $table_name) | ||
{ | ||
return $this->setName($name)->setTableName($table_name); | ||
} | ||
|
||
/** | ||
* Название highload-блока. | ||
* @param string $name | ||
* @return $this | ||
*/ | ||
public function setName($name) | ||
{ | ||
$this->fields['NAME'] = $name; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Название таблицы с элементами highload-блока. | ||
* @param string $table_name | ||
* @return $this | ||
*/ | ||
public function setTableName($table_name) | ||
{ | ||
$this->fields['TABLE_NAME'] = $table_name; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Установить локализацию | ||
* @param $lang | ||
* @param $text | ||
* @return HighloadBlock | ||
*/ | ||
public function setLang($lang, $text) | ||
{ | ||
$this->lang[$lang] = $text; | ||
|
||
return $this; | ||
} | ||
} |
Oops, something went wrong.