Files
crm.clientright.ru/crm_extensions/file_storage/api/setup_folders.php

68 lines
1.7 KiB
PHP

<?php
/**
* API для создания структуры папок в Nextcloud
*/
// Подключаем конфигурацию
$config = require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../NextcloudClient.php';
// Устанавливаем заголовки
header('Content-Type: application/json; charset=utf-8');
// Включаем отображение ошибок
error_reporting(E_ALL);
ini_set('display_errors', 1);
try {
$nextcloudClient = new NextcloudClient($config['nextcloud']);
// Создаем структуру папок
$folders = [
'/crm2/CRM_Documents',
'/crm2/CRM_Documents/Documents',
'/crm2/CRM_Documents/Templates',
'/crm2/CRM_Documents/Archive'
];
$results = [];
foreach ($folders as $folder) {
try {
$result = $nextcloudClient->createFolder($folder);
$results[$folder] = [
'success' => $result['success'],
'message' => $result['success'] ? 'Папка создана' : $result['error']
];
} catch (Exception $e) {
$results[$folder] = [
'success' => false,
'message' => $e->getMessage()
];
}
}
echo json_encode([
'success' => true,
'message' => 'Структура папок настроена',
'results' => $results,
'config' => [
'base_url' => $config['nextcloud']['base_url'],
'active_folder' => $config['nextcloud']['active_folder']
]
]);
} catch (Exception $e) {
http_response_code(500);
echo json_encode([
'success' => false,
'error' => $e->getMessage()
]);
}
?>