|
@@ -1,7 +1,7 @@
|
|
|
<?php
|
|
<?php
|
|
|
|
|
|
|
|
include 'phpexcel/PHPExcel.php';
|
|
include 'phpexcel/PHPExcel.php';
|
|
|
-include 'db.php';
|
|
|
|
|
|
|
+include '../db.php';
|
|
|
|
|
|
|
|
ini_set('memory_limit', '256M');
|
|
ini_set('memory_limit', '256M');
|
|
|
|
|
|
|
@@ -73,52 +73,52 @@ for($c = 0; $c < count($companies); $c++)
|
|
|
|
|
|
|
|
|
|
|
|
|
//go through each one
|
|
//go through each one
|
|
|
- foreach($files as $filename)
|
|
|
|
|
|
|
+ foreach($files as $full_path)
|
|
|
{
|
|
{
|
|
|
- processFile($filename, $id_company);
|
|
|
|
|
|
|
+ processFile($full_path, $id_company);
|
|
|
echo PHP_EOL;
|
|
echo PHP_EOL;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-function processFile($filename, $id_company)
|
|
|
|
|
|
|
+function processFile($full_path, $id_company)
|
|
|
{
|
|
{
|
|
|
global $dbh;
|
|
global $dbh;
|
|
|
|
|
|
|
|
- if(!file_exists($filename))
|
|
|
|
|
|
|
+ if(!file_exists($full_path))
|
|
|
{
|
|
{
|
|
|
echo "file doesn't exist" . PHP_EOL;
|
|
echo "file doesn't exist" . PHP_EOL;
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ $dir = dirname($full_path);
|
|
|
|
|
+ $filename = basename($full_path);
|
|
|
|
|
|
|
|
|
|
+ $file_size = filesize($full_path);
|
|
|
|
|
+ $file_hash = md5_file($full_path);
|
|
|
|
|
|
|
|
- $file_size = filesize($filename);
|
|
|
|
|
- $file_hash = md5_file($filename);
|
|
|
|
|
|
|
|
|
|
|
|
+ //first try to find if the file exists
|
|
|
|
|
+ $stmt_file = $dbh->prepare(
|
|
|
|
|
+ "SELECT id_file
|
|
|
|
|
+ FROM file
|
|
|
|
|
+ WHERE filename = :filename
|
|
|
|
|
+ AND md5_hash = :file_hash
|
|
|
|
|
+ AND size = :file_size");
|
|
|
|
|
+
|
|
|
$params = array(
|
|
$params = array(
|
|
|
- ':id_company' => $id_company,
|
|
|
|
|
':filename' => $filename,
|
|
':filename' => $filename,
|
|
|
- ':file_size' => $file_size,
|
|
|
|
|
- ':file_hash' => $file_hash
|
|
|
|
|
|
|
+ ':file_hash' => $file_hash,
|
|
|
|
|
+ ':file_size' => $file_size
|
|
|
);
|
|
);
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- //first try to find if the file exists
|
|
|
|
|
- $stmt_file = $dbh->prepare("SELECT id_file
|
|
|
|
|
- FROM file
|
|
|
|
|
- WHERE id_company = :id_company
|
|
|
|
|
- AND filename = :filename
|
|
|
|
|
- AND md5_hash = :file_hash
|
|
|
|
|
- AND size = :file_size");
|
|
|
|
|
|
|
|
|
|
$stmt_file->execute($params);
|
|
$stmt_file->execute($params);
|
|
|
-
|
|
|
|
|
$rows = $stmt_file->fetchAll(PDO::FETCH_ASSOC);
|
|
$rows = $stmt_file->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ //figure out if we are reprocessing
|
|
|
if(count($rows))
|
|
if(count($rows))
|
|
|
{
|
|
{
|
|
|
$id_file = $rows[0]['id_file'];
|
|
$id_file = $rows[0]['id_file'];
|
|
@@ -127,8 +127,16 @@ function processFile($filename, $id_company)
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
//report file processed
|
|
//report file processed
|
|
|
- $stmt_file = $dbh->prepare("INSERT INTO file (id_company, filename, md5_hash, size)
|
|
|
|
|
- VALUES (:id_company, :filename, :file_hash, :file_size)");
|
|
|
|
|
|
|
+ $stmt_file = $dbh->prepare("INSERT INTO file (id_company, dir, filename, md5_hash, size)
|
|
|
|
|
+ VALUES (:id_company, :dir, :filename, :file_hash, :file_size)");
|
|
|
|
|
+
|
|
|
|
|
+ $params = array(
|
|
|
|
|
+ ':id_company' => $id_company,
|
|
|
|
|
+ ':dir' => dirname($full_path),
|
|
|
|
|
+ ':filename' => basename($filename),
|
|
|
|
|
+ ':file_size' => $file_size,
|
|
|
|
|
+ ':file_hash' => $file_hash
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
if(!$stmt_file->execute($params))
|
|
if(!$stmt_file->execute($params))
|
|
|
{
|
|
{
|
|
@@ -143,9 +151,7 @@ function processFile($filename, $id_company)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- //TODO: check if we already processed this file
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ //insert row
|
|
|
$stmt_row = $dbh->prepare("INSERT INTO file_row (
|
|
$stmt_row = $dbh->prepare("INSERT INTO file_row (
|
|
|
id_file, row_number,
|
|
id_file, row_number,
|
|
|
division, consignee, date_called_in, dispatch_number, shipper, date_ready,
|
|
division, consignee, date_called_in, dispatch_number, shipper, date_ready,
|
|
@@ -187,7 +193,7 @@ function processFile($filename, $id_company)
|
|
|
|
|
|
|
|
|
|
|
|
|
// figure out which type it is
|
|
// figure out which type it is
|
|
|
- $type = PHPExcel_IOFactory::identify($filename);
|
|
|
|
|
|
|
+ $type = PHPExcel_IOFactory::identify($full_path);
|
|
|
|
|
|
|
|
// create an excel reader object
|
|
// create an excel reader object
|
|
|
$reader = PHPExcel_IOFactory::createReader($type);
|
|
$reader = PHPExcel_IOFactory::createReader($type);
|
|
@@ -197,7 +203,7 @@ function processFile($filename, $id_company)
|
|
|
echo "xls detected as: $type" . PHP_EOL;
|
|
echo "xls detected as: $type" . PHP_EOL;
|
|
|
|
|
|
|
|
// load the file
|
|
// load the file
|
|
|
- $excel = $reader->load($filename);
|
|
|
|
|
|
|
+ $excel = $reader->load($full_path);
|
|
|
|
|
|
|
|
// pull the 'call details' worksheet, which should be the only one
|
|
// pull the 'call details' worksheet, which should be the only one
|
|
|
$sheet = $excel->getSheet(0);
|
|
$sheet = $excel->getSheet(0);
|