|
|
|
|
#!/usr/bin/php -q
|
|
|
|
|
<?php
|
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
|
ini_set('display_errors', "On");
|
|
|
|
|
|
|
|
|
|
include 'configCliente.php';
|
|
|
|
|
include 'funcoes.php';
|
|
|
|
|
include('util/util.php');
|
|
|
|
|
include 'funcoes/shared.php';
|
|
|
|
|
|
|
|
|
|
$query = '';
|
|
|
|
|
$cliId = 0;
|
|
|
|
|
$inTran = 0;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
CarregaArquivos($pg_local);
|
|
|
|
|
echo "Instala<EFBFBD><EFBFBD>o da portabilidade foi conclu<EFBFBD>da com sucesso!\n";
|
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
|
|
|
|
|
|
echo $ex->getMessage();
|
|
|
|
|
}
|
|
|
|
|
@pg_close($conn);
|
|
|
|
|
|
|
|
|
|
function Desconpacta($origem, $destino, $type = "gz") {
|
|
|
|
|
switch ($type) {
|
|
|
|
|
case "gz" : $cmd = "xzvf";
|
|
|
|
|
break;
|
|
|
|
|
case "bz2": $cmd = "xjvf";
|
|
|
|
|
break;
|
|
|
|
|
default: $cmd = "xzvf";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
$result = true;
|
|
|
|
|
$cmd = sprintf("tar -%s %s -C %s 2>/dev/null", $cmd, $origem, $destino);
|
|
|
|
|
|
|
|
|
|
system($cmd, $result);
|
|
|
|
|
$arquivoPorta = "portabilidade.csv";
|
|
|
|
|
return file_exists($destino . $arquivoPorta);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CarregaArquivos($pgLocal) {
|
|
|
|
|
$db = dbConnect($pgLocal);
|
|
|
|
|
@pg_query($db, 'begin');
|
|
|
|
|
/*
|
|
|
|
|
* Deleta a tabela de dados atuais.
|
|
|
|
|
*/
|
|
|
|
|
echo "Apagando a tabela de portabilidade!\n";
|
|
|
|
|
$query = "truncate table portabilidade;";
|
|
|
|
|
$result = @pg_query($db, $query);
|
|
|
|
|
if (!$result)
|
|
|
|
|
throw new Exception(GetExcept("N<EFBFBD>o foi possivel apagar a tabela portabilidade!"));
|
|
|
|
|
|
|
|
|
|
$query = 'DROP INDEX "idxPortabilidadeTel"';
|
|
|
|
|
$result = @pg_query($db, $query);
|
|
|
|
|
if (!$result)
|
|
|
|
|
throw new Exception(GetExcept("N<EFBFBD>o foi possivel apagar idxtelDoadora!"));
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Importando a tabela portabilidade.
|
|
|
|
|
*/
|
|
|
|
|
echo "Importando a tabela de portabilidade!\n";
|
|
|
|
|
$file = DIRETORIO_DOWNLOAD_CLIENTE . "portabilidade.csv";
|
|
|
|
|
|
|
|
|
|
system("chown postgres:postgres $file");
|
|
|
|
|
$query = "COPY portabilidade FROM '$file' WITH DELIMITER AS ',' QUOTE '\"' CSV\n";
|
|
|
|
|
$result = @pg_query($db, $query);
|
|
|
|
|
if (!$result)
|
|
|
|
|
throw new Exception(GetExcept("N<EFBFBD>o foi possivel importar tabela portabilidade!"));
|
|
|
|
|
|
|
|
|
|
$query = 'CREATE INDEX "idxPortabilidadeTel" ON portabilidade USING btree (tel_doadora);';
|
|
|
|
|
$result = @pg_query($db, $query);
|
|
|
|
|
if (!$result)
|
|
|
|
|
throw new Exception(GetExcept("N<EFBFBD>o foi possivel criar indice idxtelDoadora!"));
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Importando a tabela prefixos.
|
|
|
|
|
*/
|
|
|
|
|
$file = DIRETORIO_DOWNLOAD_CLIENTE . "prefixos.csv";
|
|
|
|
|
if (file_exists($file)) {
|
|
|
|
|
echo "Apagando a tabela de prefixos!\n";
|
|
|
|
|
$query = "truncate table prefixos;";
|
|
|
|
|
$result = @pg_query($db, $query);
|
|
|
|
|
if (!$result)
|
|
|
|
|
throw new Exception(GetExcept("N<EFBFBD>o foi possivel apagar a tabela prefixos!"));
|
|
|
|
|
|
|
|
|
|
echo "Importando a tabela de prefixos!\n";
|
|
|
|
|
$query = "COPY prefixos FROM '$file' WITH DELIMITER AS ',' QUOTE '\"' CSV\n";
|
|
|
|
|
$result = @pg_query($db, $query);
|
|
|
|
|
if (!$result)
|
|
|
|
|
throw new Exception(GetExcept("N<EFBFBD>o foi possivel importar tabela prefixos!"));
|
|
|
|
|
}
|
|
|
|
|
@pg_query($db, 'commit');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function VerificaDirDownload($dir) {
|
|
|
|
|
if (!file_exists($dir)) {
|
|
|
|
|
system("mkdir -p $dir");
|
|
|
|
|
system("chmod 777 -R $dir");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return file_exists($dir);
|
|
|
|
|
}
|
|
|
|
|
?>
|