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

Proper filename handling and touching dates

parent 823b896b
......@@ -29,7 +29,7 @@ function bulid_field_desc($field_head,$field_desc) {
case 'N' : $datatype = 'A'; break;
}
$field = $key[0];
if ($field == 'BORESERV') {
if ( $field === 'BORESERV') {
$fi++;
$field .= $fi;
}
......@@ -287,19 +287,25 @@ function parse_import_files_directory_descriptions( $path ): array {
* Parse description file for attributes.
*/
function parse_desc_file( $filename ) {
$handle = fopen( $filename, 'r');
$handle = fopen( $filename, 'rb');
$path = pathinfo($filename);
$filesize = filesize( $filename);
@$filesize = 0+filesize( $filename);
$buffer = myEncodeFunctionANSI( fread( $handle, $filesize ) );
fclose( $handle );
$curr = 0;
// Do the assignments.
$match[$curr]['filename'] = $filename;
preg_match_all('/^Artikeluppdatering från Finfo(\s+)(.*)$/um', $buffer, $matches);
@$match[$curr]['updated'] = $matches[2][0];
if(!isset($matches[2][0])) {
preg_match_all('/^Avtalsuppdatering från Finfo(\s+)(.*)$/um', $buffer, $matches);
$match[$curr]['updated'] = $matches[2][0];
}
preg_match_all('/^Filnamn:(\s+)(.*)$/um', $buffer, $matches);
$match[$curr]['zipfil'] = $path['dirname'].'\\'.@trim($matches[2][0]).'.zip';
$match[$curr]['filesize'] = @0+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]);
......@@ -420,6 +426,7 @@ $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';
$directory['DONE'] = $directory['base'].'DONE';
prlog("\n\nStarting parser: ");
prlog( 'Setup start: ' );
......@@ -445,6 +452,7 @@ foreach ( $desc_files as $filename ) {
prlog ($zipfile['levnr'].TAB.$zipfile['levname'].TAB.$zipfile['nya'].' nya artiklar');
$filtyp = $zipfile['filtyp'];
$updated = $zipfile['updated'];
$zipfil = $zipfile['zipfil'];
$zipfil_path_info = pathinfo( $zipfil );
$zipfil_namn = $zipfil_path_info['basename'];
......@@ -456,6 +464,7 @@ foreach ( $desc_files as $filename ) {
// Figure out what import filter to use;
$process = true;
// Do the uppacking etc.
if ( false !== stripos( $zipfile['ordertyp'], 'Manuell' ) || $zipfile['nya'] > 0 ) {
// Bolist with New articles.
$bo_destination_subdir = 'bolist_nya';
......@@ -481,19 +490,31 @@ foreach ( $desc_files as $filename ) {
$bo_vilma_identifier = $bo_destination_unpack . 'F' . $zipfil_num . '.TXT';
}
// Parse and move everything where it needs to be
$updated_split = explode( ' ', $updated);
$updated_date = $updated_split[0];
$updated_time = $updated_split[3];
prlog( '*** Updated: ' . $updated_date . ' - '. $updated_time);
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 );
$bo_vilma_typ = $lev_konvert_vilma_type[$zipfile['levnr']];
$bo_vilma_identifier_new = $bo_destination_unpack .'V' . $zipfil_num.'_' . $bo_vilma_typ.'_'. $zipfile['levname'] . '.TXT';
@$bo_vilma_typ = 0+$lev_konvert_vilma_type[$zipfile['levnr']];
$bo_vilma_identifier_new = str_replace( ' ', '_', $bo_destination_unpack .'V' . $zipfil_num.'_' . $bo_vilma_typ.'_'. $bo_destination_subdir .'_'. str_replace( "'", '_',str_replace( "/", '_',str_replace( "&", '_',str_replace( "\\", '_',$zipfile['levname'])))) . '.TXT');
rename( $bo_vilma_identifier, $bo_vilma_identifier_new);
prlog( $touch_command = 'touch -c -t '.str_replace( ' ', '',str_replace( '-', '', substr( $updated_date, 2)).''.str_replace( ':', '',substr( $updated_time, 0, -2))).' '.$bo_vilma_identifier_new );
exec( $touch_command );
prlog( $bo_vilma_identifier_new);
prlog ("Vilma typ: " . $bo_vilma_typ );
} else {
prlog( $bo_vilma_identifier);
$bo_vilma_typ = 'FIN04';
$bo_vilma_identifier_new = str_replace( ' ', '_', $bo_destination_unpack .'F' . $zipfil_num.'_' . $bo_vilma_typ.'_'. $bo_destination_subdir .'_'. str_replace( "'", '_',str_replace( "/", '_',str_replace( "&", '_',str_replace( "\\", '_',$zipfile['levname'])))) . '.TXT');
rename( $bo_vilma_identifier, $bo_vilma_identifier_new);
prlog( $touch_command = 'touch -c -t '.str_replace( ' ', '',str_replace( '-', '', substr( $updated_date, 2)).''.str_replace( ':', '',substr( $updated_time, 0, -2))).' '.$bo_vilma_identifier_new );
exec( $touch_command );
prlog( $bo_vilma_identifier_new);
prlog("Vilma typ: EJ VILMA");
}
unlink( $bo_source_zip_path );
......@@ -503,6 +524,8 @@ foreach ( $desc_files as $filename ) {
}
prlog( '-------------------------------------------------');
}
// Set last runtime tag
exec('touch '.$bo_destination_unpack.'---last-run---'.date( 'Y-m-d_H:i:s' ));
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