@@ -32,10 +32,11 @@ $arangodb = new connection(require __DIR__ . '/../settings/arangodb.php');
function generateLabel ( string $name ) : string
function generateLabel ( string $name ) : string
{
{
return match ( $name ) {
return match ( $name ) {
'id' , 'ID' , 'Т Т ' => 'id' ,
'id' , 'ID' , 'Т Т ' , '№ТТ' => 'id' ,
'type' , 'ТИП' , 'Тип' , 'тип' => 'type' ,
'type' , 'ТИП' , 'Тип' , 'тип' , 'ФОРМАТ' => 'type' ,
'name' , 'ДИРЕКТОР' , 'Директор' , 'директор' => 'name' ,
'name' , 'ДИРЕКТОР' , 'Директор' , 'директор' , 'ДИРЕКТОР Т Т ' => 'name' ,
'address' , 'АДРЕС' , 'Адрес' , 'адрес' => 'address' ,
'address' , 'АДРЕС' , 'Адрес' , 'адрес' => 'address' ,
'city' , 'город' , 'Город' , 'Направление' => 'city' ,
default => $name
default => $name
};
};
}
}
@@ -47,6 +48,7 @@ function degenerateLabel(string $name): string
'ТИП' , 'type' => 'ТИП' ,
'ТИП' , 'type' => 'ТИП' ,
'ДИРЕКТОР' , 'name' => 'ДИРЕКТОР' ,
'ДИРЕКТОР' , 'name' => 'ДИРЕКТОР' ,
'АДРЕС' , 'address' => 'АДРЕС' ,
'АДРЕС' , 'address' => 'АДРЕС' ,
'city' => 'ГОРОД' ,
default => $name
default => $name
};
};
}
}
@@ -72,7 +74,7 @@ function init(array $row, bool $reverse = false): array
}
}
function sync ( Row & $row , string $city = 'Красноярск' ): void
function sync ( Row & $row ) : void
{
{
global $arangodb ;
global $arangodb ;
@@ -82,8 +84,11 @@ function sync(Row &$row, string $city = 'Красноярск'): void
// Инициализация ФИО
// Инициализация ФИО
$name = explode ( ' ' , $_row [ 'name' ]);
$name = explode ( ' ' , $_row [ 'name' ]);
if ( collection :: init ( $arangodb -> session , 'markets' ))
// Инициализация идентификатора
if ( ! empty ( $_row [ 'id' ]) && $market = collection :: search ( $arangodb -> session , sprintf ( " FOR d IN markets FILTER d.id == '%s' RETURN d " , $_row [ 'id' ]))) {
if ( empty ( $id = preg_replace ( '/([^^\d]?)(\d+).*/u' , 'K$2' , $_row [ 'id' ]))) return ;
if ( collection :: init ( $arangodb -> session , 'market' ))
if ( $market = collection :: search ( $arangodb -> session , sprintf ( " FOR d IN market FILTER d.id == '%s' RETURN d " , $id ))) {
// Найдена запись магазина (строки) в базе данных и включен режим перезаписи (приоритет - google sheets)
// Найдена запись магазина (строки) в базе данных и включен режим перезаписи (приоритет - google sheets)
if ( false && $market -> transfer_to_sheets ) {
if ( false && $market -> transfer_to_sheets ) {
@@ -119,13 +124,13 @@ function sync(Row &$row, string $city = 'Красноярск'): void
/* // Обновление инстанции документа в базе данных
/* // Обновление инстанции документа в базе данных
document::update($arangodb->session, $market); */
document::update($arangodb->session, $market); */
} else if (
} else if (
$market = collection :: search (
$market = collection :: search (
$arangodb -> session ,
$arangodb -> session ,
sprintf (
sprintf (
" FOR d IN markets FILTER d._id == '%s' RETURN d " ,
" FOR d IN market FILTER d._id == '%s' RETURN d " ,
document :: write ( $arangodb -> session , 'markets ' , [
document :: write ( $arangodb -> session , 'market' , [
'id' => $_row [ 'id' ] ? ? '' ,
'id' => $id ,
'type' => $_row [ 'type' ] ? ? '' ,
'type' => $_row [ 'type' ] ? ? '' ,
'name' => [
'name' => [
'first' => $name [ 1 ] ? ? $_row [ 'name' ] ? ? '' ,
'first' => $name [ 1 ] ? ? $_row [ 'name' ] ? ? '' ,
@@ -133,7 +138,7 @@ function sync(Row &$row, string $city = 'Красноярск'): void
'last' => $name [ 2 ] ? ? ''
'last' => $name [ 2 ] ? ? ''
],
],
'address' => $_row [ 'address' ] ? ? '' ,
'address' => $_row [ 'address' ] ? ? '' ,
'city' => $city ,
'city' => $_row [ 'city' ] ? ? '' ,
'active' => true
'active' => true
])
])
)
)
@@ -181,13 +186,13 @@ $client->setAuthConfig($settings);
$api = new Sheets ( $client );
$api = new Sheets ( $client );
foreach ( $sheets as $sheet ) {
foreach ( $sheets as $sheet ) {
$rows = ( new Flow ()) -> read ( new GoogleSheetExtractor ( $api , $document , new Columns ( $sheet , 'A ' , 'D ' ), true , 1000 , 'row' ));
$rows = ( new Flow ()) -> read ( new GoogleSheetExtractor ( $api , $document , new Columns ( $sheet , 'B ' , 'F ' ), true , 1000 , 'row' ));
$i = 1 ;
$i = 1 ;
foreach ( $rows -> fetch ( 5000 ) as $row ) {
foreach ( $rows -> fetch ( 5000 ) as $row ) {
++ $i ;
if ( ++ $i === 2 ) continue ;
$buffer = $row ;
$buffer = $row ;
sync ( $row , $sheet );
sync ( $row );
if ( $buffer !== $row ) {
if ( $buffer !== $row ) {
/* $api->spreadsheets_values->update(
/* $api->spreadsheets_values->update(
$document,
$document,