Commit eca8a67d authored by Danny Froberg's avatar Danny Froberg 💬
Browse files

New sorting

parent 788c72c2
......@@ -7,6 +7,9 @@
require_once 'includes/definitions.php';
require_once __DIR__ . '/vendor/autoload.php';
use Hug\Sftp\Sftp as Sftp;
// Enable logfile
define( 'LOGFILE', 'P:/FINFO_Import/logfile.txt');
$fp = fopen( LOGFILE, 'wb+');
/**
* Build unpack descriptor.
......@@ -126,10 +129,10 @@ function parse($file_name) {
$line = unpack( $descriptor, $lines );
array_walk_recursive($line, 'myEncodeFunction');
if ( ! $line ) {
echo "\nError:\n";
var_dump( $descriptor );
prlog("\nError:\n");
prlog(print_r( $descriptor , true) );
//var_dump( $buffer_conv );
var_dump( $line );
prlog(print_r( $line , true) );
exit();
}
$buffer .= sprintf( '%06d', $pretty_numbered_lines) ."\t";
......@@ -296,7 +299,7 @@ function parse_desc_file( $filename ) {
preg_match_all('/^Filnamn:(\s+)(.*)$/um', $buffer, $matches);
$match[$curr]['zipfil'] = $path['dirname'].'\\'.@trim($matches[2][0]).'.zip';
$match[$curr]['filesize'] = filesize($match[$curr]['zipfil']);
$match[$curr]['filesize'] = @0+filesize($match[$curr]['zipfil']);
preg_match_all('/^Filtyp:(\s+)(\w+)$/um', $buffer, $matches);
$match[$curr]['filtyp'] = @trim($matches[2][0]);
......@@ -355,9 +358,11 @@ function setup_reciever_directories() {
$directory['base'] = 'P:/FINFO_Import/';
$directory['nyabol'] = $directory['base'].'bolist_nya';
$directory['nyabol3'] = $directory['base'].'bolist_nya/vilma_3';
$directory['nyabol4'] = $directory['base'].'bolist_nya/vilma_4';
$directory['nyabol5'] = $directory['base'].'bolist_nya/vilma_5';
$directory['updbol'] = $directory['base'].'bolist_upd';
$directory['updbol3'] = $directory['base'].'bolist_upd/vilma_3';
$directory['updbol4'] = $directory['base'].'bolist_upd/vilma_4';
$directory['updbol5'] = $directory['base'].'bolist_upd/vilma_5';
$directory['other'] = $directory['base'].'other';
......@@ -397,16 +402,22 @@ function unzip($source, $destination) {
* @param $string
*/
function prlog($string) {
echo date( 'Y-m-d H:i:s' ) . ' ' . $string . "\n";
global $fp;
$log_item = date( 'Y-m-d H:i:s' ) . ' ' . $string . "\n";
echo $log_item;
fwrite( $fp, $log_item);
}
define('TAB', "\t");
$directory['base'] = 'P:/FINFO_Import/';
$directory['nyabol'] = $directory['base'].'bolist_nya';
$directory['nyabol3'] = $directory['base'].'bolist_nya/vilma_3';
$directory['nyabol4'] = $directory['base'].'bolist_nya/vilma_4';
$directory['nyabol5'] = $directory['base'].'bolist_nya/vilma_5';
$directory['updbol'] = $directory['base'].'bolist_upd';
$directory['updbol3'] = $directory['base'].'bolist_upd/vilma_3';
$directory['updbol4'] = $directory['base'].'bolist_upd/vilma_4';
$directory['updbol5'] = $directory['base'].'bolist_upd/vilma_5';
$directory['other'] = $directory['base'].'other';
......@@ -431,7 +442,8 @@ foreach ( $desc_files as $filename ) {
$parsed = parse_desc_file( $filename );
foreach ( $parsed as $zipfile ) {
echo $zipfile['levnr'].TAB.$zipfile['levname'].TAB.$zipfile['nya'].' nya artiklar'.PHP_EOL;
prlog ($zipfile['levnr'].TAB.$zipfile['levname'].TAB.$zipfile['nya'].' nya artiklar');
$filtyp = $zipfile['filtyp'];
$zipfil = $zipfile['zipfil'];
$zipfil_path_info = pathinfo( $zipfil );
......@@ -469,15 +481,18 @@ foreach ( $desc_files as $filename ) {
$bo_vilma_identifier = $bo_destination_unpack . 'F' . $zipfil_num . '.TXT';
}
// Parse and move everything where it needs to be
if(true || $process === true ) {
if( true || $process === true ) {
if ( $zipfil_ext === 'zip' && unzip( $bo_source_zip_path, $bo_destination_unpack ) ) {
//unlink( $zipfile['filename'] );
// Only do VILMA classification if it's an actual VILMA file.
if( $bo_destination_subdir !== 'other') {
$bo_vilma_typ = identify_vilma_filter( $bo_vilma_identifier );
echo "Vilma typ: " . $bo_vilma_typ . "\n\n";
$bo_vilma_identifier_new = $bo_destination_unpack .'F' . $zipfil_num.'_' . $bo_vilma_typ.'_'. $zipfile['levname'] . '.TXT';
rename( $bo_vilma_identifier, $bo_vilma_identifier_new);
prlog( $bo_vilma_identifier_new);
prlog ("Vilma typ: " . $bo_vilma_typ );
} else {
echo "Vilma typ: EJ VILMA\n\n";
prlog("Vilma typ: EJ VILMA");
}
unlink( $bo_source_zip_path );
......@@ -485,4 +500,6 @@ foreach ( $desc_files as $filename ) {
}
}
}
prlog( "\nParser complete: ");
\ No newline at end of file
prlog( "\nParser complete: ");
// Finalize and cleanup
fclose( $fp);
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment