Created
April 3, 2017 18:33
-
-
Save primogf/a80df568177df491793ecdc7a3a3715a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$query = "SELECT | |
dc.id_dado_coletado, | |
dc.id_projeto_elemento, | |
dc.valor_identificador, | |
d.caminho_file, | |
proj.nome as projeto, | |
pre.des_status as processo | |
FROM erp_dado_coletado dc | |
INNER JOIN erp_dado_coletado_item dci ON dci.id_dado_coletado = dc.id_dado_coletado AND dci.tabela_registro = 'Document' | |
INNER JOIN Document d ON id_documento = dci.id_registro | |
INNER JOIN com_projeto_elemento pre ON (pre.id_projeto_elemento = dc.id_projeto_elemento AND pre.stat <> 0) | |
INNER JOIN com_projeto proj ON (proj.id_projeto = pre.id_projeto AND proj.stat <> 0) | |
INNER JOIN EnergyDistributorMainData con ON (con.id_parceiro = proj.id_parceiro AND con.stat <> 0) | |
INNER JOIN erp_elemento ele ON (pre.id_elemento = ele.id_elemento AND pre.stat <> 0) | |
INNER JOIN erp_parceiro p ON (p.id_parceiro = proj.id_parceiro AND p.stat <> 0) | |
WHERE (dc.stat != 0 AND proj.id_projeto = 161 AND pre.id_elemento = 2) | |
ORDER BY dc.valor_identificador"; | |
$con = new PDO("mysql:host=localhost;dbname=xxx;port=3306", "xxx", "xxx", array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8')); | |
$stmt = $con->prepare($query); | |
$stmt->execute(array("id"=>"161","elemento"=>"2")); | |
$file = new \SplFileObject("/home/marcio/Downloads/data/" . Date("YmdHis") . "_download.sh", "w"); | |
@chmod("/home/marcio/Downloads/data/" . Date("YmdHis") . "_download.sh", "w", 0777); | |
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { | |
$filename = $storage | |
. DIRECTORY_SEPARATOR . strtolower($row['projeto']) | |
. DIRECTORY_SEPARATOR . preg_replace("/\s+/", "_", strtolower($row['processo'])) | |
. DIRECTORY_SEPARATOR . strtolower($row["valor_identificador"]) | |
. DIRECTORY_SEPARATOR . preg_replace("/^(.*)(\/)((.*)(\.)(.*))$/", "$3", $row['caminho_file']); | |
if (!file_exists($filename)) { | |
// $cmd = "aws s3 cp \"s3://gestorfox{$row['caminho_file']}\" \"{$filename}\"" . PHP_EOL; | |
$var = explode('/',$row['caminho_file']); | |
$ultima = end($var); | |
$cmd = "wget \"http://gestorfox.s3.amazonaws.com{$row['caminho_file']}\" -x " . PHP_EOL; | |
$file->fwrite($cmd); | |
echo $cmd; | |
} | |
} | |
$file->fflush(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment