Сделал сохранением свойств в таблице, работаю над их удалением
This commit is contained in:
parent
0e50565f63
commit
e71c62b1ab
@ -40,9 +40,6 @@ class CustomExportProps extends Controller
|
||||
$props = $requestData['properties'];
|
||||
$profileId = $requestData['profileId'];
|
||||
|
||||
$dbConnection = Application::getInstance()->getConnection();
|
||||
try {
|
||||
$dbConnection->startTransaction();
|
||||
foreach ($props as $catalogId => $propsArray) {
|
||||
$catalogCustomProps = [];
|
||||
foreach ($propsArray as $property) {
|
||||
@ -51,12 +48,7 @@ class CustomExportProps extends Controller
|
||||
'title' => $property['title']
|
||||
];
|
||||
}
|
||||
$settingsService->setCustomProps($profileId, $catalogId, $catalogCustomProps);
|
||||
}
|
||||
|
||||
$dbConnection->commitTransaction();
|
||||
} catch (\Throwable $e) {
|
||||
$dbConnection->rollbackTransaction();
|
||||
$settingsService->saveCustomProps($profileId, $catalogId, $catalogCustomProps);
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,11 +63,6 @@ class CustomExportProps extends Controller
|
||||
$props = $requestData['properties'];
|
||||
$profileId = $requestData['profileId'];
|
||||
|
||||
$dbConnection = Application::getInstance()->getConnection();
|
||||
|
||||
try {
|
||||
$dbConnection->startTransaction();
|
||||
|
||||
foreach ($props as $catalogId => $propsArray) {
|
||||
$catalogCustomProps = [];
|
||||
foreach ($propsArray as $property) {
|
||||
@ -84,43 +71,7 @@ class CustomExportProps extends Controller
|
||||
'title' => $property['title']
|
||||
];
|
||||
}
|
||||
$settingsService->deleteCustomProps($profileId, $catalogId, $catalogCustomProps);
|
||||
// $filePath = sprintf(
|
||||
// '%s/%s_profileId_%s_catalogId_%s.txt',
|
||||
// $_SERVER['DOCUMENT_ROOT'] . '/local',
|
||||
// 'icml_property_retailcrm',
|
||||
// $profileId,
|
||||
// $catalogId
|
||||
// );
|
||||
// $fileContent = file_get_contents($filePath);
|
||||
//
|
||||
// foreach ($propsArray as $property) {
|
||||
// $propStringToDelete = PHP_EOL . $property['code'] . ' = ' . $property['title'];
|
||||
// $fileContent = str_replace($propStringToDelete, '', $fileContent);
|
||||
// }
|
||||
// file_put_contents($filePath, $fileContent);
|
||||
|
||||
$settingsService->removeCustomProps($profileId, $catalogId, $catalogCustomProps);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$dbConnection->rollbackTransaction();
|
||||
// Добавить возврат ответа с ошибкой
|
||||
}
|
||||
|
||||
// foreach ($props as $catalogId => $propsArray) {
|
||||
// $filePath = sprintf(
|
||||
// '%s/%s_profileId_%s_catalogId_%s.txt',
|
||||
// $_SERVER['DOCUMENT_ROOT'] . '/local',
|
||||
// 'icml_property_retailcrm',
|
||||
// $profileId,
|
||||
// $catalogId
|
||||
// );
|
||||
// $fileContent = file_get_contents($filePath);
|
||||
//
|
||||
// foreach ($propsArray as $property) {
|
||||
// $propStringToDelete = PHP_EOL . $property['code'] . ' = ' . $property['title'];
|
||||
// $fileContent = str_replace($propStringToDelete, '', $fileContent);
|
||||
// }
|
||||
// file_put_contents($filePath, $fileContent);
|
||||
|
||||
}
|
||||
}
|
@ -816,30 +816,63 @@ class SettingsService
|
||||
return unserialize(COption::GetOptionString(self::MODULE_ID, $optionName));
|
||||
}
|
||||
|
||||
public function deleteCustomProps(
|
||||
public function removeCustomProps(
|
||||
string $profileId,
|
||||
string $catalogId,
|
||||
array $propsToDelete
|
||||
): void
|
||||
{
|
||||
): void {
|
||||
$currentCatalogProps = $this->getCustomProps($profileId, $catalogId);
|
||||
$updatedCatalogProps = array_diff($currentCatalogProps, $propsToDelete);
|
||||
$updatedCatalogProps = array_values(array_filter(
|
||||
$currentCatalogProps,
|
||||
fn ($currentProp) => !in_array($currentProp, $propsToDelete)
|
||||
));
|
||||
|
||||
if (empty($updatedCatalogProps)) {
|
||||
$this->setCustomProps($profileId, $catalogId, []);
|
||||
$this->removeCustomPropsOptionEntry($profileId, $catalogId);
|
||||
} else {
|
||||
$this->updateCustomPropsOptionEntry($profileId, $catalogId, $updatedCatalogProps);
|
||||
}
|
||||
}
|
||||
|
||||
$this->setCustomProps($profileId, $catalogId, $updatedCatalogProps);
|
||||
public function updateCustomPropsOptionEntry(
|
||||
string $profileId,
|
||||
string $catalogId,
|
||||
array $updatedProps
|
||||
) {
|
||||
$this->removeCustomPropsOptionEntry($profileId, $catalogId);
|
||||
$this->setCustomPropsOptionEntry($profileId, $catalogId, $updatedProps);
|
||||
}
|
||||
|
||||
public function setCustomProps(
|
||||
private function removeCustomPropsOptionEntry($profileId, $catalogId)
|
||||
{
|
||||
$optionName = $this->getCustomPropsOptionName($profileId, $catalogId);
|
||||
$delRes = COption::RemoveOption(self::MODULE_ID, $optionName);
|
||||
}
|
||||
|
||||
private function setCustomPropsOptionEntry(
|
||||
string $profileId,
|
||||
string $catalogId,
|
||||
array $props
|
||||
): void {
|
||||
)
|
||||
{
|
||||
$optionName = $this->getCustomPropsOptionName($profileId, $catalogId);
|
||||
$propsString = serialize($props);
|
||||
|
||||
COption::SetOptionString(self::MODULE_ID, $optionName, $propsString);
|
||||
$setResult = COption::SetOptionString(self::MODULE_ID, $optionName, $propsString);
|
||||
}
|
||||
|
||||
public function saveCustomProps(
|
||||
string $profileId,
|
||||
string $catalogId,
|
||||
array $newProps
|
||||
): void {
|
||||
$currentProps = $this->getCustomProps($profileId, $catalogId);
|
||||
|
||||
if (empty($currentProps)) {
|
||||
$this->setCustomPropsOptionEntry($profileId, $catalogId, $newProps);
|
||||
} else {
|
||||
$updatedProps = array_merge($currentProps, $newProps);
|
||||
$this->updateCustomPropsOptionEntry($profileId, $catalogId, $updatedProps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user