fix for new sheet

This commit is contained in:
Arsen Mirzaev Tatyano-Muradovich 2023-06-16 05:14:29 +07:00
parent 9a23715012
commit a0426fad60
2 changed files with 46 additions and 90 deletions

96
composer.lock generated
View File

@ -4,20 +4,20 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "11076f3d90ec7beb78f179975cadfba0", "content-hash": "a68510590091701e9c9d83f85929c2ca",
"packages": [ "packages": [
{ {
"name": "firebase/php-jwt", "name": "firebase/php-jwt",
"version": "v6.5.0", "version": "v6.7.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/firebase/php-jwt.git", "url": "https://github.com/firebase/php-jwt.git",
"reference": "e94e7353302b0c11ec3cfff7180cd0b1743975d2" "reference": "71278f20b0a623389beefe87a641d03948a38870"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/firebase/php-jwt/zipball/e94e7353302b0c11ec3cfff7180cd0b1743975d2", "url": "https://api.github.com/repos/firebase/php-jwt/zipball/71278f20b0a623389beefe87a641d03948a38870",
"reference": "e94e7353302b0c11ec3cfff7180cd0b1743975d2", "reference": "71278f20b0a623389beefe87a641d03948a38870",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -65,9 +65,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/firebase/php-jwt/issues", "issues": "https://github.com/firebase/php-jwt/issues",
"source": "https://github.com/firebase/php-jwt/tree/v6.5.0" "source": "https://github.com/firebase/php-jwt/tree/v6.7.0"
}, },
"time": "2023-05-12T15:47:07+00:00" "time": "2023-06-14T15:29:26+00:00"
}, },
{ {
"name": "flow-php/array-dot", "name": "flow-php/array-dot",
@ -299,16 +299,16 @@
}, },
{ {
"name": "google/apiclient-services", "name": "google/apiclient-services",
"version": "v0.303.0", "version": "v0.304.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/googleapis/google-api-php-client-services.git", "url": "https://github.com/googleapis/google-api-php-client-services.git",
"reference": "b9c143453a94d5e6ed7257d065dcc5662619eaf4" "reference": "6731fd0d3e2f1ff2794f36108b55c0a3480edf3d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/b9c143453a94d5e6ed7257d065dcc5662619eaf4", "url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/6731fd0d3e2f1ff2794f36108b55c0a3480edf3d",
"reference": "b9c143453a94d5e6ed7257d065dcc5662619eaf4", "reference": "6731fd0d3e2f1ff2794f36108b55c0a3480edf3d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -337,9 +337,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/googleapis/google-api-php-client-services/issues", "issues": "https://github.com/googleapis/google-api-php-client-services/issues",
"source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.303.0" "source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.304.0"
}, },
"time": "2023-06-04T01:12:12+00:00" "time": "2023-06-07T02:11:36+00:00"
}, },
{ {
"name": "google/auth", "name": "google/auth",
@ -1199,16 +1199,16 @@
}, },
{ {
"name": "phpseclib/phpseclib", "name": "phpseclib/phpseclib",
"version": "3.0.19", "version": "3.0.20",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpseclib/phpseclib.git", "url": "https://github.com/phpseclib/phpseclib.git",
"reference": "cc181005cf548bfd8a4896383bb825d859259f95" "reference": "543a1da81111a0bfd6ae7bbc2865c5e89ed3fc67"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/cc181005cf548bfd8a4896383bb825d859259f95", "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/543a1da81111a0bfd6ae7bbc2865c5e89ed3fc67",
"reference": "cc181005cf548bfd8a4896383bb825d859259f95", "reference": "543a1da81111a0bfd6ae7bbc2865c5e89ed3fc67",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1289,7 +1289,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/phpseclib/phpseclib/issues", "issues": "https://github.com/phpseclib/phpseclib/issues",
"source": "https://github.com/phpseclib/phpseclib/tree/3.0.19" "source": "https://github.com/phpseclib/phpseclib/tree/3.0.20"
}, },
"funding": [ "funding": [
{ {
@ -1305,7 +1305,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-03-05T17:13:09+00:00" "time": "2023-06-13T06:30:34+00:00"
}, },
{ {
"name": "psr/cache", "name": "psr/cache",
@ -1788,64 +1788,6 @@
"source": "https://github.com/arangodb/arangodb-php/tree/v3.8.0" "source": "https://github.com/arangodb/arangodb-php/tree/v3.8.0"
}, },
"time": "2021-06-18T12:06:02+00:00" "time": "2021-06-18T12:06:02+00:00"
},
{
"name": "webmozart/assert",
"version": "1.11.0",
"source": {
"type": "git",
"url": "https://github.com/webmozarts/assert.git",
"reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/webmozarts/assert/zipball/11cb2199493b2f8a3b53e7f19068fc6aac760991",
"reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991",
"shasum": ""
},
"require": {
"ext-ctype": "*",
"php": "^7.2 || ^8.0"
},
"conflict": {
"phpstan/phpstan": "<0.12.20",
"vimeo/psalm": "<4.6.1 || 4.6.2"
},
"require-dev": {
"phpunit/phpunit": "^8.5.13"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.10-dev"
}
},
"autoload": {
"psr-4": {
"Webmozart\\Assert\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Bernhard Schussek",
"email": "bschussek@gmail.com"
}
],
"description": "Assertions to validate method input/output with nice error messages.",
"keywords": [
"assert",
"check",
"validate"
],
"support": {
"issues": "https://github.com/webmozarts/assert/issues",
"source": "https://github.com/webmozarts/assert/tree/1.11.0"
},
"time": "2022-06-03T18:03:27+00:00"
} }
], ],
"packages-dev": [], "packages-dev": [],

View File

@ -32,16 +32,18 @@ $arangodb = new connection(require '../settings/arangodb.php');
function generateLabel(string $name): string function generateLabel(string $name): string
{ {
return match ($name) { return match ($name) {
'_id', 'ID' => '_id', 'created_in_sheets', 'Создано' => 'created_in_sheets',
'date', 'Дата' => 'date',
'market', 'Магазин' => 'market', 'market', 'Магазин' => 'market',
'worker', 'Сотрудник' => 'worker', 'worker', 'Сотрудник' => 'worker',
'work', 'Работа' => 'work', 'work', 'Работа' => 'work',
'date', 'Дата' => 'date',
'start', 'Начало' => 'start', 'start', 'Начало' => 'start',
'end', 'Конец' => 'end', 'end', 'Конец' => 'end',
'hours', 'Часы' => 'hours',
'confirmed', 'Подтверждено' => 'confirmed', 'confirmed', 'Подтверждено' => 'confirmed',
'commentary', 'Комментарий' => 'commentary', 'commentary', 'Комментарий' => 'commentary',
'response', 'Ответ' => 'response', 'response', 'Ответ' => 'response',
'_id', 'ID' => '_id',
default => throw new exception("Неизвестный столбец: $name") default => throw new exception("Неизвестный столбец: $name")
}; };
} }
@ -49,16 +51,18 @@ function generateLabel(string $name): string
function degenerateLabel(string $name): string function degenerateLabel(string $name): string
{ {
return match ($name) { return match ($name) {
'ID', '_id' => 'ID', 'Создано', 'created_in_sheets' => 'Создано',
'Дата', 'date' => 'Дата',
'Магазин', 'market' => 'Магазин', 'Магазин', 'market' => 'Магазин',
'Сотрудник', 'worker' => 'Сотрудник', 'Сотрудник', 'worker' => 'Сотрудник',
'Работа', 'work' => 'Работа', 'Работа', 'work' => 'Работа',
'Дата', 'date' => 'Дата',
'Начало', 'start' => 'Начало', 'Начало', 'start' => 'Начало',
'Конец', 'end' => 'Конец', 'Конец', 'end' => 'Конец',
'Часы', 'hours' => 'Часы',
'Подтверждено', 'confirmed' => 'Подтверждено', 'Подтверждено', 'confirmed' => 'Подтверждено',
'Комментарий', 'commentary' => 'Комментарий', 'Комментарий', 'commentary' => 'Комментарий',
'Ответ', 'response' => 'Ответ', 'Ответ', 'response' => 'Ответ',
'ID', '_id' => 'ID',
default => throw new exception("Неизвестный столбец: $name") default => throw new exception("Неизвестный столбец: $name")
}; };
} }
@ -84,19 +88,23 @@ function sync(Row &$row): void
// Найдена запись работы (строки) в базе данных // Найдена запись работы (строки) в базе данных
// Очистка перед записью в таблицу // Очистка перед записью в таблицу
$new = array_diff_key($work->getAll(), ['_key' => true, 'created' => true]); $new = array_diff_key($work->getAll(), ['_key' => true, 'created' => true]) + ['_id' => $work->getId()];
$buffer = $new;
// Инициализация выбранного сотрудника // Инициализация выбранного сотрудника
if (collection::init($arangodb->session, 'readinesses', true) && collection::init($arangodb->session, 'workers')) if (collection::init($arangodb->session, 'readinesses', true) && collection::init($arangodb->session, 'workers'))
$new = ['worker' => collection::search( $new = array_splice($new, 0, 2) + ['worker' => collection::search(
$arangodb->session, $arangodb->session,
sprintf( sprintf(
"FOR d IN workers LET e = (FOR e IN readinesses FILTER e._to == '%s' RETURN e._from)[0] FILTER d._id == e RETURN d", "FOR d IN workers LET e = (FOR e IN readinesses FILTER e._to == '%s' RETURN e._from)[0] FILTER d._id == e RETURN d",
$_row['_id'] $_row['_id']
) )
)->id ?? ''] + $new; )->id ?? ''] + array_slice($buffer, 2);
else throw new exception('Не удалось инициализировать коллекции'); else throw new exception('Не удалось инициализировать коллекции');
$buffer = $new;
// Инициализация магазина // Инициализация магазина
if (collection::init($arangodb->session, 'requests', true) && collection::init($arangodb->session, 'markets')) if (collection::init($arangodb->session, 'requests', true) && collection::init($arangodb->session, 'markets'))
if ($market = collection::search( if ($market = collection::search(
@ -105,12 +113,12 @@ function sync(Row &$row): void
"FOR d IN markets LET e = (FOR e IN requests FILTER e._to == '%s' RETURN e._from)[0] FILTER d._id == e RETURN d", "FOR d IN markets LET e = (FOR e IN requests FILTER e._to == '%s' RETURN e._from)[0] FILTER d._id == e RETURN d",
$_row['_id'] $_row['_id']
) )
)) $new = ['market' => $market->id] + $new; )) $new = array_splice($new, 0, 2) + ['market' => $market->id] + array_splice($buffer, 2);
else throw new exception('Не удалось найти магазин'); else throw new exception('Не удалось найти магазин');
else throw new exception('Не удалось инициализировать коллекции'); else throw new exception('Не удалось инициализировать коллекции');
// Запись идентификатора только что созданной записи в базе данных для записи в таблицу // Замена NULL на пустую строку
$new = ['_id' => $work->getId()] + $new; foreach ($new as $key => &$value) if ($value === null) $value = '';
// Реинициализация строки с новыми данными по ссылке (приоритет из базы данных) // Реинициализация строки с новыми данными по ссылке (приоритет из базы данных)
if ($_row !== $new) $row = $row->set((new Flow())->read(From::array([init($new, true)]))->fetch(1)[0]->get('row')); if ($_row !== $new) $row = $row->set((new Flow())->read(From::array([init($new, true)]))->fetch(1)[0]->get('row'));
@ -154,8 +162,14 @@ function sync(Row &$row): void
else throw new exception('Не удалось создать готовность сотрудника'); else throw new exception('Не удалось создать готовность сотрудника');
} }
// Запись идентификатора только что созданной инстанции документа в базе данных
$_row['_id'] = $work->getId();
// Замена NULL на пустую строку
foreach ($_row as $key => &$value) if ($value === null) $value = '';
// Реинициализация строки с новыми данными по ссылке (приоритет из базы данных) // Реинициализация строки с новыми данными по ссылке (приоритет из базы данных)
$row = $row->set((new Flow())->read(From::array([init(['_id' => $work->getId()] + $_row, true)]))->fetch(1)[0]->get('row')); $row = $row->set((new Flow())->read(From::array([init($_row, true)]))->fetch(1)[0]->get('row'));
} else return; } else return;
else throw new exception('Не удалось инициализировать коллекцию'); else throw new exception('Не удалось инициализировать коллекцию');
} }
@ -171,7 +185,7 @@ $client->setAuthConfig($settings);
foreach ($sheets as $sheet) { foreach ($sheets as $sheet) {
$sheets = new Sheets($client); $sheets = new Sheets($client);
$rows = (new Flow())->read(new GoogleSheetExtractor($sheets, $document, new Columns($sheet, 'A', 'J'), true, 1000, 'row')); $rows = (new Flow())->read(new GoogleSheetExtractor($sheets, $document, new Columns($sheet, 'A', 'L'), true, 1000, 'row'));
$i = 1; $i = 1;
@ -182,7 +196,7 @@ foreach ($sheets as $sheet) {
if ($buffer !== $row) if ($buffer !== $row)
$sheets->spreadsheets_values->update( $sheets->spreadsheets_values->update(
$document, $document,
"$sheet!A$i:J$i", "$sheet!A$i:L$i",
new ValueRange(['values' => [array_values($row->entries()->toArray()['row'])]]), new ValueRange(['values' => [array_values($row->entries()->toArray()['row'])]]),
['valueInputOption' => 'USER_ENTERED'] ['valueInputOption' => 'USER_ENTERED']
); );