You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

104 lines
3.0 KiB

#!/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ção da portabilidade foi concluí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ão foi possivel apagar a tabela portabilidade!"));
$query = 'DROP INDEX "idxPortabilidadeTel"';
$result = @pg_query($db, $query);
if (!$result)
throw new Exception(GetExcept("Nã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ã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ã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ã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ã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);
}
?>