|
|
@@ -92,14 +92,28 @@ class Route_UrlAction_BiAuditGenerate extends RouteBase {
|
|
|
<?php
|
|
|
}
|
|
|
?>
|
|
|
- <tr>
|
|
|
- <td><input type="checkbox" name="reloadCache"/></td>
|
|
|
- <td colspan=6>Odśwież cache (wymagane w przypadku, gdy dokonano dowolnych zmian w tabelach pracowników/kontrahentów)</td>
|
|
|
- </tr>
|
|
|
</tbody>
|
|
|
</table>
|
|
|
</div>
|
|
|
</div>
|
|
|
+ <div class="form-group">
|
|
|
+ <label class="col-sm-2 control-label">
|
|
|
+ Odśwież cache
|
|
|
+ </label>
|
|
|
+ <div class="col-sm-2">
|
|
|
+ <select name="reloadCache" class="form-control">
|
|
|
+ <option value="no" selected>Nie</option>
|
|
|
+ <option value="part">Częściowe</option>
|
|
|
+ <option value="full">Pełne</option>
|
|
|
+ </select>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="form-group">
|
|
|
+ <div class="col-sm-offset-2 col-sm-10">
|
|
|
+ Częściowe odświeżenie wymagane w przypadku, gdy dokonano dowolnych zmian w tabelach pracowników/kontrahentów.<br/>
|
|
|
+ Pełne odświeżenie wymagane w przypadku modyfikacji baz KRS lub CEiDG (UWAGA - trwa to wiele godzin)
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
<div class="form-group">
|
|
|
<div class="col-sm-12">
|
|
|
<div class="containter" style="text-align:center">
|
|
|
@@ -144,14 +158,15 @@ function toggle(source) {
|
|
|
|
|
|
$sqlUpdate = ['FILE_STATUS' => 'TO_GENERATE'];
|
|
|
|
|
|
- $reloadCache = V::get('reloadCache', 'off', $_POST);
|
|
|
- if ($reloadCache == 'on') $sqlUpdate['BI_analiza_reloadCache'] = 'Y';
|
|
|
- else $sqlUpdate['BI_analiza_reloadCache'] = 'N';
|
|
|
+ $reloadCache = V::get('reloadCache', 'no', $_POST);
|
|
|
+ $reloadCacheAvailable = ['Full', 'Part', 'No'];
|
|
|
+ if (!in_array($reloadCache, $reloadCacheAvailable)) throw new Exception("Błąd formularza!");
|
|
|
+ $sqlUpdate['BI_analiza_reloadCache'] = $reloadCache;
|
|
|
|
|
|
- $query = "select count(*) from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where BI_analiza_reloadCache = 'Y'";
|
|
|
+ $query = "select count(*) from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where BI_analiza_reloadCache in ('Full', 'Part')";
|
|
|
$result = DB::getPDO()->fetchValue($query);
|
|
|
if ($result) $sqlUpdate['FILE_STATUS_info'] = 'Oczekuje na odświeżenie cache (wymagane dla innego rekordu)';
|
|
|
- elseif ($reloadCache == 'on') $sqlUpdate['FILE_STATUS_info'] = 'Oczekuje na odświeżenie cache';
|
|
|
+ elseif ($reloadCache != 'No') $sqlUpdate['FILE_STATUS_info'] = 'Oczekuje na odświeżenie cache';
|
|
|
else $sqlUpdate['FILE_STATUS_info'] = "Oczekuje na wygenerowanie powiązań";
|
|
|
|
|
|
if ($this->powiazanie) { // wyzwolone z poziomu tabeli BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA - aktualizujemy istniejący rekord
|
|
|
@@ -315,14 +330,24 @@ where `REMOTE_PRIMARY_KEY` = '{$this->SOURCE['ID']}'";
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="form-group">
|
|
|
- <label class="col-sm-4 control-label">Odśwież cache (wymagane w przypadku, gdy dokonano dowolnych zmian w tabelach pracowników/kontrahentów)</label>
|
|
|
- <div class="col-sm-1">
|
|
|
+ <label class="col-sm-4 control-label">
|
|
|
+ Odśwież cache
|
|
|
+ </label>
|
|
|
+ <div class="col-sm-2">
|
|
|
<select name="reloadCache" class="form-control">
|
|
|
- <option value="on">Tak</option>
|
|
|
- <option value="off" selected>Nie</option>
|
|
|
+ <option value="no" selected>Nie</option>
|
|
|
+ <option value="part">Częściowe</option>
|
|
|
+ <option value="full">Pełne</option>
|
|
|
</select>
|
|
|
</div>
|
|
|
</div>
|
|
|
+ <div class="form-group">
|
|
|
+ <div class="col-sm-offset-4 col-sm-8">
|
|
|
+ Częściowe odświeżenie wymagane w przypadku, gdy dokonano dowolnych zmian w tabelach pracowników/kontrahentów.<br/>
|
|
|
+ Pełne odświeżenie wymagane w przypadku modyfikacji baz KRS lub CEiDG (UWAGA - trwa to wiele godzin)
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
<div class="form-group">
|
|
|
<div class="col-sm-12">
|
|
|
<div class="containter" style="text-align:center">
|
|
|
@@ -502,7 +527,7 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
|
|
|
|
|
|
### Sprawdzenie czy któryś rekord wymaga odświeżenia cache
|
|
|
$doGenerate = true;
|
|
|
- $query = "select ID from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where BI_analiza_reloadCache = 'Y' and FILE_STATUS = 'TO_GENERATE'";
|
|
|
+ $query = "select ID from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where BI_analiza_reloadCache in ('Full', 'Part') and FILE_STATUS = 'TO_GENERATE'";
|
|
|
$result = DB::getPDO()->fetchAll($query);
|
|
|
if ($result) {
|
|
|
$doGenerate = false;
|
|
|
@@ -557,7 +582,10 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
|
|
|
$sqlArr = [
|
|
|
'FILE_STATUS_info' => 'W trakcie odświeżania cache',
|
|
|
];
|
|
|
- file_put_contents($reloadCachePhpFile, generatePhpScript('doReloadCache()'));
|
|
|
+
|
|
|
+ $query = "select count(*) from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA where BI_analiza_reloadCache = 'Full' and FILE_STATUS = 'TO_GENERATE'";
|
|
|
+ $fullReloadCache = (DB::getPDO()->fetchValue($query) > 0);
|
|
|
+ file_put_contents($reloadCachePhpFile, generatePhpScript("doReloadCache({$fullReloadCache})"));
|
|
|
shell_exec('su - root -c "php ' . $reloadCachePhpFile . ' > ' . $reloadCacheLogFile. ' 2>&1 &"');
|
|
|
}
|
|
|
}
|
|
|
@@ -655,7 +683,7 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private function reloadCache_reTeryt() {
|
|
|
+ private function reloadCache_reTeryt($full = false) {
|
|
|
|
|
|
Lib::loadClass('Teryt');
|
|
|
|
|
|
@@ -671,6 +699,22 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
|
|
|
'miejscowosc' => 'miejscowosc',
|
|
|
'ulica' => 'ulica',
|
|
|
],
|
|
|
+ 'BI_audit_KRS' => [
|
|
|
+ 'wojewodztwo' => 'S_wojewodztwo',
|
|
|
+ 'powiat' => 'S_powiat',
|
|
|
+ 'gmina' => 'S_gmina',
|
|
|
+ 'miejscowosc' => 'A_miejscowosc',
|
|
|
+ 'ulica' => 'A_ulica',
|
|
|
+ 'kodPocztowy' => 'A_kod',
|
|
|
+ ],
|
|
|
+ 'BI_audit_CEIDG' => [
|
|
|
+ 'wojewodztwo' => 'wojewodztwo',
|
|
|
+ 'powiat' => 'powiat',
|
|
|
+ 'gmina' => 'gmina',
|
|
|
+ 'miejscowosc' => 'miejscowosc',
|
|
|
+ 'ulica' => 'ulica',
|
|
|
+ 'kodPocztowy' => 'kodPocztowy',
|
|
|
+ ],
|
|
|
];
|
|
|
|
|
|
$columns = ['kodPocztowy', 'miejscowosc', 'ulica'];
|
|
|
@@ -695,11 +739,15 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if ($full) {
|
|
|
+ reTeryt('BI_audit_KRS');
|
|
|
+ reTeryt('BI_audit_CEIDG');
|
|
|
+ }
|
|
|
reTeryt('BI_audit_ENERGA_RUM_KONTRAHENCI');
|
|
|
reTeryt('BI_audit_ENERGA_PRACOWNICY_adresy');
|
|
|
}
|
|
|
|
|
|
- private function reloadCache_updateAll() {
|
|
|
+ private function reloadCache_updateAll($full = false) {
|
|
|
$tables = [
|
|
|
'BI_audit_ENERGA_PRACOWNICY' => [
|
|
|
'fields' => [
|
|
|
@@ -707,6 +755,7 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
|
|
|
'regon' => 'regon',
|
|
|
'pesel' => 'pesel',
|
|
|
],
|
|
|
+ 'base' => '0',
|
|
|
//'where' => '',
|
|
|
],
|
|
|
'BI_audit_ENERGA_PRACOWNICY_adresy' => [
|
|
|
@@ -716,6 +765,7 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
|
|
|
'nrDomu' => 'nrBudynku',
|
|
|
'nrLokalu' => 'nrLokalu',
|
|
|
],
|
|
|
+ 'base' => '0',
|
|
|
//'where' => '',
|
|
|
],
|
|
|
'BI_audit_ENERGA_RUM_KONTRAHENCI' => [
|
|
|
@@ -728,6 +778,7 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
|
|
|
'nrDomu' => 'Numer_budynku',
|
|
|
'nrLokalu' => 'Numer_mieszkania_lokalu',
|
|
|
],
|
|
|
+ 'base' => '0',
|
|
|
'where' => "ownCompany != 'Y'",
|
|
|
],
|
|
|
'BI_audit_KW_requested_person' => [
|
|
|
@@ -737,39 +788,130 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
|
|
|
'nip' => 'Seller_person_NIP',
|
|
|
'regon' => 'Seller_person_REGON',
|
|
|
],
|
|
|
+ 'base' => '0',
|
|
|
//'where' => '',
|
|
|
],
|
|
|
];
|
|
|
- $queries[] = "delete from BI_audit_ALL where BASE = 0";
|
|
|
- $queries[] = "delete from BI_audit_ALL_ref where BASE = 0";
|
|
|
- $queries[] = "delete from BI_audit_ALL_ref_RELATIONS where BASE = 0";
|
|
|
+
|
|
|
+ $tables_full = [
|
|
|
+ 'BI_audit_CEIDG' => [
|
|
|
+ 'fields' => [
|
|
|
+ 'nip' => 'nip',
|
|
|
+ 'regon' => 'regon',
|
|
|
+ 'TERYT_SYM' => 'TERYT_SYM',
|
|
|
+ 'TERYT_SYM_UL' => 'TERYT_SYM_UL',
|
|
|
+ 'nrDomu' => 'budynek',
|
|
|
+ 'nrLokalu' => 'lokal',
|
|
|
+ ],
|
|
|
+ 'base' => '1',
|
|
|
+ ],
|
|
|
+ 'BI_audit_CEIDG_pelnomocnicy' => [
|
|
|
+ 'fields' => [
|
|
|
+ 'nip' => 'nip',
|
|
|
+ 'TERYT_SYM' => 'TERYT_SYM',
|
|
|
+ 'TERYT_SYM_UL' => 'TERYT_SYM_UL',
|
|
|
+ 'nrDomu' => 'budynek',
|
|
|
+ 'nrLokalu' => 'lokal',
|
|
|
+ ],
|
|
|
+ 'base' => '1',
|
|
|
+ ],
|
|
|
+ 'BI_audit_CEIDG_powiazania' => [
|
|
|
+ 'fields' => [
|
|
|
+ 'nip' => 'nip',
|
|
|
+ 'regon' => 'regon',
|
|
|
+ ],
|
|
|
+ 'base' => '1',
|
|
|
+ ],
|
|
|
+ 'BI_audit_KRS' => [
|
|
|
+ 'fields' => [
|
|
|
+ 'krs' => 'krs',
|
|
|
+ 'nip' => 'nip',
|
|
|
+ 'regon' => 'regon',
|
|
|
+ 'TERYT_SYM' => 'TERYT_SYM',
|
|
|
+ 'TERYT_SYM_UL' => 'TERYT_SYM_UL',
|
|
|
+ 'nrDomu' => 'A_nrDomu',
|
|
|
+ 'nrLokalu' => 'A_nrLokalu',
|
|
|
+ ],
|
|
|
+ 'base' => '1',
|
|
|
+ ],
|
|
|
+ 'BI_audit_KRS_company' => [
|
|
|
+ 'fields' => [
|
|
|
+ 'regon' => 'regon',
|
|
|
+ 'krs' => 'krs',
|
|
|
+ ],
|
|
|
+ 'base' => '1',
|
|
|
+ ],
|
|
|
+ 'BI_audit_KRS_person' => [
|
|
|
+ 'fields' => [
|
|
|
+ 'pesel' => 'pesel',
|
|
|
+ ],
|
|
|
+ 'base' => '1',
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+
|
|
|
+ if ($full) {
|
|
|
+ $tables = array_merge($tables, $tables_full);
|
|
|
+ $fullWhere = '1 = 1';
|
|
|
+ } else {
|
|
|
+ $fullWhere = 'BASE = 0';
|
|
|
+ }
|
|
|
+
|
|
|
+ $queries[] = "delete from BI_audit_ALL where {$fullWhere}";
|
|
|
+ $queries[] = "delete from BI_audit_ALL_ref where {$fullWhere}";
|
|
|
+ $queries[] = "delete from BI_audit_ALL_ref_RELATIONS where {$fullWhere}";
|
|
|
foreach ($tables as $name => $table) {
|
|
|
if (isset($table['where']) && $table['where']) $where = "where {$table['where']}";
|
|
|
else $where = '';
|
|
|
- $queries[] = "insert into BI_audit_ALL (REMOTE_TABLE, REMOTE_ID, " . implode(", ", array_keys($table['fields'])) . ") select '{$name}', ID, " . implode(", ", $table['fields']) . " from {$name} {$where}";
|
|
|
+ $queries[] = "insert into BI_audit_ALL (REMOTE_TABLE, REMOTE_ID, BASE, " . implode(", ", array_keys($table['fields'])) . ") select '{$name}', ID, '{$table['base']}', " . implode(", ", $table['fields']) . " from {$name} {$where}";
|
|
|
}
|
|
|
- $queries[] = "update BI_audit_ALL set nrDomu = substring(nrDomu, 1, position('/' in nrDomu) - 1), nrLokalu = substring(nrDomu, position('/' in nrDomu ) + 1) where nrDomu rlike '^[[:digit:]]+.*/[[:digit:]]+.*$' and nrLokalu is null and BASE = 0";
|
|
|
+ $queries[] = "update BI_audit_ALL set nip = null where nip = 0";
|
|
|
+ $queries[] = "update BI_audit_ALL set regon = null where regon = 0";
|
|
|
+ $queries[] = "update BI_audit_ALL set krs = null where krs = 0";
|
|
|
+ $queries[] = "update BI_audit_ALL set pesel = null where pesel = 0";
|
|
|
+ $queries[] = "update BI_audit_ALL set TERYT_SYM = null where TERYT_SYM = 0";
|
|
|
+ $queries[] = "update BI_audit_ALL set TERYT_SYM_UL = null where TERYT_SYM_UL = 0";
|
|
|
+ $queries[] = "update BI_audit_ALL set nrDomu = null where trim(nrDomu) = ''";
|
|
|
+ $queries[] = "update BI_audit_ALL set nrLokalu = null where trim(nrLokalu) = ''";
|
|
|
+ $queries[] = "update BI_audit_ALL set nrDomu = substring(nrDomu, 1, position('/' in nrDomu) - 1), nrLokalu = substring(nrDomu, position('/' in nrDomu ) + 1) where nrDomu rlike '^[[:digit:]]+.*/[[:digit:]]+.*$' and nrLokalu is null and {$fullWhere}";
|
|
|
+
|
|
|
$queries[] = "set @var = (select round(coalesce(max(ID), '0.5')) from BI_audit_ALL_ref_RELATIONS)";
|
|
|
$queries[] = "insert into BI_audit_ALL_ref_RELATIONS (ID, RELATION) select @var:=@var*2, a.RELATION from (select a.REMOTE_TABLE as RELATION from BI_audit_ALL a where a.REMOTE_TABLE not in ('BI_audit_ENERGA_RUM_KONTRAHENCI', 'BI_audit_KW_requested_person') group by a.REMOTE_TABLE) as a left join BI_audit_ALL_ref_RELATIONS r on a.RELATION = r.RELATION where r.RELATION is null";
|
|
|
$refPracownicyToPracownicyAdresy = ACL::getRefTable('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY', "default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy");
|
|
|
$queries[] = "insert into BI_audit_ALL_ref (ID1, ID2, RELATION_ID) select all1.ID, all2.ID, rel.ID from BI_audit_ALL as all1 join `{$refPracownicyToPracownicyAdresy}` as ref on all1.REMOTE_TABLE = 'BI_audit_ENERGA_PRACOWNICY' and all1.REMOTE_ID = ref.PRIMARY_KEY join BI_audit_ALL as all2 on all2.REMOTE_TABLE = 'BI_audit_ENERGA_PRACOWNICY_adresy' and ref.REMOTE_PRIMARY_KEY = all2.REMOTE_ID join BI_audit_ALL_ref_RELATIONS rel on all1.REMOTE_TABLE = rel.RELATION";
|
|
|
+ if ($full) {
|
|
|
+ $refCeidgToCeidgPelnomocnicy = ACL::getRefTable('default_db/BI_audit_CEIDG/BI_audit_CEIDG', "default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy");
|
|
|
+ $queries[] = "insert ignore into BI_audit_ALL_ref (ID1, ID2, RELATION_ID) select all1.ID, all2.ID, rel.ID from BI_audit_ALL as all1 join `{$refCeidgToCeidgPelnomocnicy}` as ref on all1.REMOTE_TABLE = 'BI_audit_CEIDG' and all1.REMOTE_ID = ref.PRIMARY_KEY join BI_audit_ALL as all2 on all2.REMOTE_TABLE = 'BI_audit_CEIDG_pelnomocnicy' and ref.REMOTE_PRIMARY_KEY = all2.REMOTE_ID join BI_audit_ALL_ref_RELATIONS rel on all1.REMOTE_TABLE = rel.RELATION";
|
|
|
+ $queries[] = "insert ignore into BI_audit_ALL_ref (ID1, ID2, RELATION_ID) select all2.ID, all1.ID, rel.ID from BI_audit_ALL as all1 join `{$refCeidgToCeidgPelnomocnicy}` as ref on all1.REMOTE_TABLE = 'BI_audit_CEIDG' and all1.REMOTE_ID = ref.PRIMARY_KEY join BI_audit_ALL as all2 on all2.REMOTE_TABLE = 'BI_audit_CEIDG_pelnomocnicy' and ref.REMOTE_PRIMARY_KEY = all2.REMOTE_ID join BI_audit_ALL_ref_RELATIONS rel on all2.REMOTE_TABLE = rel.RELATION";
|
|
|
+
|
|
|
+ $refCeidgToCeidgPowiazania = ACL::getRefTable('default_db/BI_audit_CEIDG/BI_audit_CEIDG', "default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania");
|
|
|
+ $queries[] = "insert ignore into BI_audit_ALL_ref (ID1, ID2, RELATION_ID) select all1.ID, all2.ID, rel.ID from BI_audit_ALL as all1 join `{$refCeidgToCeidgPowiazania}` as ref on all1.REMOTE_TABLE = 'BI_audit_CEIDG' and all1.REMOTE_ID = ref.PRIMARY_KEY join BI_audit_ALL as all2 on all2.REMOTE_TABLE = 'BI_audit_CEIDG_powiazania' and ref.REMOTE_PRIMARY_KEY = all2.REMOTE_ID join BI_audit_ALL_ref_RELATIONS rel on all1.REMOTE_TABLE = rel.RELATION";
|
|
|
+ $queries[] = "insert ignore into BI_audit_ALL_ref (ID1, ID2, RELATION_ID) select all2.ID, all1.ID, rel.ID from BI_audit_ALL as all1 join `{$refCeidgToCeidgPowiazania}` as ref on all1.REMOTE_TABLE = 'BI_audit_CEIDG' and all1.REMOTE_ID = ref.PRIMARY_KEY join BI_audit_ALL as all2 on all2.REMOTE_TABLE = 'BI_audit_CEIDG_powiazania' and ref.REMOTE_PRIMARY_KEY = all2.REMOTE_ID join BI_audit_ALL_ref_RELATIONS rel on all2.REMOTE_TABLE = rel.RELATION";
|
|
|
+
|
|
|
+ $refKrsToKrsCompany = ACL::getRefTable('default_db/BI_audit_KRS/BI_audit_KRS', "default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company");
|
|
|
+ $queries[] = "insert ignore into BI_audit_ALL_ref (ID1, ID2, RELATION_ID) select all1.ID, all2.ID, rel.ID from BI_audit_ALL as all1 join `{$refKrsToKrsCompany}` as ref on all1.REMOTE_TABLE = 'BI_audit_KRS' and all1.REMOTE_ID = ref.PRIMARY_KEY join BI_audit_ALL as all2 on all2.REMOTE_TABLE = 'BI_audit_KRS_company' and ref.REMOTE_PRIMARY_KEY = all2.REMOTE_ID join BI_audit_ALL_ref_RELATIONS rel on all1.REMOTE_TABLE = rel.RELATION";
|
|
|
+ $queries[] = "insert ignore into BI_audit_ALL_ref (ID1, ID2, RELATION_ID) select all2.ID, all1.ID, rel.ID from BI_audit_ALL as all1 join `{$refKrsToKrsCompany}` as ref on all1.REMOTE_TABLE = 'BI_audit_KRS' and all1.REMOTE_ID = ref.PRIMARY_KEY join BI_audit_ALL as all2 on all2.REMOTE_TABLE = 'BI_audit_KRS_company' and ref.REMOTE_PRIMARY_KEY = all2.REMOTE_ID join BI_audit_ALL_ref_RELATIONS rel on all2.REMOTE_TABLE = rel.RELATION";
|
|
|
+
|
|
|
+ $refKrsToKrsPerson = ACL::getRefTable('default_db/BI_audit_KRS/BI_audit_KRS', "default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person");
|
|
|
+ $queries[] = "insert ignore into BI_audit_ALL_ref (ID1, ID2, RELATION_ID) select all1.ID, all2.ID, rel.ID from BI_audit_ALL as all1 join `{$refKrsToKrsPerson}` as ref on all1.REMOTE_TABLE = 'BI_audit_KRS' and all1.REMOTE_ID = ref.PRIMARY_KEY join BI_audit_ALL as all2 on all2.REMOTE_TABLE = 'BI_audit_KRS_person' and ref.REMOTE_PRIMARY_KEY = all2.REMOTE_ID join BI_audit_ALL_ref_RELATIONS rel on all1.REMOTE_TABLE = rel.RELATION";
|
|
|
+ $queries[] = "insert ignore into BI_audit_ALL_ref (ID1, ID2, RELATION_ID) select all2.ID, all1.ID, rel.ID from BI_audit_ALL as all1 join `{$refKrsToKrsPerson}` as ref on all1.REMOTE_TABLE = 'BI_audit_KRS' and all1.REMOTE_ID = ref.PRIMARY_KEY join BI_audit_ALL as all2 on all2.REMOTE_TABLE = 'BI_audit_KRS_person' and ref.REMOTE_PRIMARY_KEY = all2.REMOTE_ID join BI_audit_ALL_ref_RELATIONS rel on all2.REMOTE_TABLE = rel.RELATION";
|
|
|
+ }
|
|
|
|
|
|
foreach ($queries as $query) DB::getPDO()->query($query);
|
|
|
- $BiAuditRelations = new BiAuditRelations();
|
|
|
- $query = "select ID from BI_audit_ALL where BASE = 0";
|
|
|
+ $BiAuditRelations = new BiAuditRelations($full);
|
|
|
+ $query = "select ID from BI_audit_ALL where {$fullWhere}";
|
|
|
$result = DB::query($query);
|
|
|
while ($row = DB::fetch($result)) $BiAuditRelations->findRelations($row->ID);
|
|
|
}
|
|
|
|
|
|
- public function doReloadCache() {
|
|
|
+ public function doReloadCache($full = false) {
|
|
|
$powiazaniaDirLocation = $this->getMainDirectory();
|
|
|
$tasksDirLocation = $powiazaniaDirLocation . "/.tasks";
|
|
|
$reloadCachePidFile = $tasksDirLocation . "/reloadCache.pid";
|
|
|
$reloadCacheResultFile = $tasksDirLocation . "/reloadCache.result";
|
|
|
file_put_contents($reloadCachePidFile, getmypid());
|
|
|
try {
|
|
|
- $this->reloadCache_reTeryt();
|
|
|
- $this->reloadCache_updateAll();
|
|
|
+ $this->reloadCache_reTeryt($full);
|
|
|
+ $this->reloadCache_updateAll($full);
|
|
|
file_put_contents($reloadCacheResultFile, "ok");
|
|
|
} catch (Exception $e) {
|
|
|
file_put_contents($reloadCacheResultFile, $e->getMessage());
|
|
|
@@ -844,6 +986,16 @@ Router::getRoute("UrlAction_BiAuditGenerate")->' . $function . ';
|
|
|
$sqlList['ActivateBiAuditGenerate'] = <<<SQL
|
|
|
REPLACE INTO `CRM_CONFIG` (`CONF_KEY`,`CONF_VAL`) VALUES ('module_BiAudit','on');
|
|
|
SQL;
|
|
|
+ $sqlList['ChangeStructure1'] = <<<SQL
|
|
|
+ALTER TABLE `BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA` CHANGE `BI_analiza_reloadCache` `BI_analiza_reloadCache` ENUM('Y','N','Full','Part','No') NOT NULL DEFAULT 'No';
|
|
|
+SQL;
|
|
|
+ $sqlList['ChangeStructure2'] = <<<SQL
|
|
|
+UPDATE `BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA` SET `BI_analiza_reloadCache` = IF (`BI_analiza_reloadCache` = 'Y', 'Part', 'No');
|
|
|
+SQL;
|
|
|
+ $sqlList['ChangeStructure3'] = <<<SQL
|
|
|
+ALTER TABLE `BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA` CHANGE `BI_analiza_reloadCache` `BI_analiza_reloadCache` ENUM('Full','Part','No') NOT NULL DEFAULT 'No';
|
|
|
+SQL;
|
|
|
+
|
|
|
|
|
|
$db = DB::getDB();
|
|
|
if ($db->has_errors()) {
|
|
|
@@ -861,6 +1013,7 @@ SQL;
|
|
|
|
|
|
class BiAuditRelations {
|
|
|
private $RELATIONS_ID = [];
|
|
|
+ private $full;
|
|
|
|
|
|
private $relations = [
|
|
|
'nip' => ['nip'],
|
|
|
@@ -873,7 +1026,8 @@ class BiAuditRelations {
|
|
|
private $destTables = ['BI_audit_ENERGA_RUM_KONTRAHENCI', 'BI_audit_KW_requested_person'];
|
|
|
private $sourceTable = ['BI_audit_ENERGA_PRACOWNICY', 'BI_audit_ENERGA_PRACOWNICY_adresy'];
|
|
|
|
|
|
- public function __construct() {
|
|
|
+ public function __construct($full = false) {
|
|
|
+ $this->full = $full;
|
|
|
$query = "select * from BI_audit_ALL_ref_RELATIONS";
|
|
|
$result = DB::getPDO()->fetchAll($query);
|
|
|
foreach ($result as $row) $this->RELATIONS_ID[$row['RELATION']] = $row['ID'];
|
|
|
@@ -912,8 +1066,10 @@ class BiAuditRelations {
|
|
|
}
|
|
|
if (!$joins) return false;
|
|
|
|
|
|
+ if ($this->full) $where = "where t1.ID = {$ID} and t2.ID > {$ID}";
|
|
|
+ else $where = "where t1.ID = {$ID} and (t2.BASE = 1 or t2.ID > {$ID})";
|
|
|
$query = "select t2.ID as ID, t1.REMOTE_TABLE as REMOTE_TABLE_1, t2.REMOTE_TABLE as REMOTE_TABLE_2 {$items} " .
|
|
|
- "from BI_audit_ALL t1 join BI_audit_ALL t2 on " . implode(" or ", $joins) . " where t1.ID = {$ID} and (t2.BASE = 1 or t2.ID > {$ID})";
|
|
|
+ "from BI_audit_ALL t1 join BI_audit_ALL t2 on " . implode(" or ", $joins) . " {$where}";
|
|
|
$result = DB::getPDO()->fetchAll($query);
|
|
|
foreach ($result as $row) {
|
|
|
$relationID = 0;
|