· 7 years ago · Oct 19, 2018, 09:02 AM
1<?php
2/***********************************************************
3indexing.management.class.php
4Product : DAM
5Version : 1.0
6Release : 2 Alpha 14
7Date Created : Tue May 25 10:01:32 IDT 2010
8Developed By : Samer Radwan PHP Department Layout International
9All Rights Reserved , Layout International COPYRIGHT 2010
10
11Indexing errors:
12================
13
141 :: Folder didn't behave as a directory or PHP wasn't able to see as directory
152 :: Folder is not readable
163 :: Error while registering data for a specific folder during InitialMasterScan()
174 :: Error while registering data for a specific folder during LongQuickIndexScan()
185 :: Error while updating folder parameters
196 :: Error while deleting DB content
207 :: Folder is not accessible
218 :: Folder is in excluded list
22
23************************************************************/
24
25class IndexManager extends request {
26
27 var $sl_id = null; // Stores the value of storage location id
28 var $sl_path = null; // Stores the full path of a storage location
29 var $sl_name = null; // Stores the name of a storage location
30 var $sl_excluded_folders = array(); // Stores the excluded folders of a storage location
31 var $dir_id = null; // Stores a specific directory ID. Mainly used if re-indexing from inside the system
32 var $dir_path = null; // Stores a specific directory path. Mainly used if re-indexing from inside the system
33 var $fldrs_to_index_obj = null; // File manager class object. Holds folders flagged as 1 (i.e: For Indexing)
34 var $fldrs_content_obj = null; // File manager class object. Hold contents of folders
35 var $folder_contents = null;
36 var $physical_fldr_content = null;
37 var $fldrs_files_queries = array(); // Defines array of query values. Used in Quick/Long index
38
39 var $new_fldr_added = false;
40
41 var $unique_file_name = null; // Holds name of unique file created A7PRO
42
43 var $log_folder_path = null; // Stores the path of the log folder
44 var $log_file_name = null; // Stores log file name
45 var $log_date = null;
46
47 var $time_log = false; // Indicates if we wish to log the time a script is taking
48 var $usage_type = 'maintenance'; // Indicated if we are using the class from the maintenance or internal application
49 var $display_log = true;
50
51 var $print_helper_obj = null;
52 var $quick_or_long_index = null;
53
54 /**
55 * Class Constructor
56 *
57 * @param INT $sl_id :: Storage location id of the location we wish to index
58 * @return IndexManager
59 */
60 function IndexManager ( $sl_id, $dir_id = 0, $dir_path = null )
61 {
62 $this->print_helper_obj = new PrintHelper();
63
64 $this->SetSystemFileTable(); // Set name of system files table
65 $this->SetLogFileName( date('Y-m-d H') . "00" );
66 $this->SetLogDate( date("h:i:s A") );
67 $this->SetUniqueFileName( '.a7pro2' );
68
69 if( $sl_id > 0 )
70 {
71 $this->SetStorageLocationID( $sl_id );
72 $this->SetDirID( $dir_id );
73 $this->SetDirPath( $dir_path );
74
75 /** Define Storage location */
76 $sm_obj = new StorageManager();
77 $query_cond = " WHERE sl.sl_id = '" . $this->GetStorageLocationID() . "'";
78 $sm_obj->members_array = array( "sl.sl_id","sl.sl_path", "sl.sl_name", "sl.sl_user_name", "sl.sl_password", "sl.sl_network_drive", "sl.sl_network_folder", "sl.sl_excluded_folder" );
79 $sm_obj->GetStorageLocations( $query_cond );
80
81 $this->SetLogFolderPath( ( is_dir( '../../backup/' ) ? "../../" : DA_BASE_SRC ) . 'backup/logs/indexing_logs/' . $sm_obj->data["sl_sl_name"][0] . "/" );
82 $this->SetInvalidCharactersPath( "invalid_characters/" );
83 $this->SetStorageLocationdData( $sm_obj );
84 $sm_obj->MountStorageLocation( $sm_obj ); // In case storage location had a username and password
85 unset( $sm_obj );
86 }
87 }
88
89 /**
90 * Set system_files table name. For now it will return system_files
91 * In the future if each storage location is to be stored in a different table
92 * ==> The name will vary based on the storage location
93 *
94 * @return void
95 */
96 function SetSystemFileTable ()
97 {
98 global $tableCollab;
99 $tableCollab["system_files"] = DBHelper::BuildSystemTableFileName();
100 }
101
102 /**
103 * Set Log Folder path
104 *
105 * @param $path :: Main directory path of the indexing log folder
106 * @return void
107 */
108 function SetLogFolderPath ( $path )
109 {
110 $this->log_folder_path = $path;
111 }
112
113 /**
114 * Set Invalid Characters path
115 *
116 * @param $path :: Main directory path of the Invalid Characters
117 * @return void
118 */
119 function SetInvalidCharactersPath ( $path )
120 {
121 $this->invalid_characters_path = $path;
122 }
123
124 /**
125 * Set Log file name
126 *
127 * @param String $file_name
128 */
129 function SetLogFileName ( $file_name )
130 {
131 $this->log_file_name = $file_name;
132 }
133
134 /**
135 * Set log date that is used when printing to CMD or File or Browser
136 *
137 * @param Date $date
138 */
139 function SetLogDate ( $date )
140 {
141 $this->log_date = $date;
142 }
143
144 /**
145 * Set quick or long index
146 *
147 * @param Date $quick_or_long_index
148 */
149 function SetQuickOrLongIndex ( $quick_or_long_index )
150 {
151 $this->quick_or_long_index = $quick_or_long_index;
152 }
153
154 /**
155 * Set time log flag
156 *
157 * @param Booloean $time_log
158 */
159 function SetTimeLog ( $time_log )
160 {
161 $this->time_log = $time_log;
162 }
163
164 /**
165 * Set usage type
166 *
167 * @param String $usage_type
168 */
169 function SetUsageType ( $usage_type )
170 {
171 $this->usage_type = $usage_type;
172 }
173
174 /**
175 * Set Display log flag
176 *
177 * @param Boolean $display_log
178 */
179 function SetDisplayLog ( $display_log )
180 {
181 $this->display_log = $display_log;
182 }
183
184 /**
185 * Set Storage Location data from Storage Manager object
186 *
187 * @param StorageManager object $sm_obj
188 * @return void
189 */
190 function SetStorageLocationdData ( &$sm_obj )
191 {
192 $this->SetStorageLocationPath( $sm_obj->data["sl_sl_path"][0] );
193 $this->SetStorageLocationName( $sm_obj->data["sl_sl_name"][0] );
194 $this->SetStorageExcludedFolders( $sm_obj->data["sl_sl_excluded_folder"][0] );
195 }
196
197 /**
198 * Set name of unique file created by A7PRO
199 *
200 * @param String $file_name
201 */
202 function SetUniqueFileName ( $file_name )
203 {
204 $this->unique_file_name = $file_name;
205 }
206
207 /**
208 * Set Storage Location ID
209 *
210 * @param INT $sl_id
211 */
212 function SetStorageLocationID ( $sl_id )
213 {
214 $this->sl_id = $sl_id;
215 }
216
217 /**
218 * Set Directory ID :: Mainly used if re-indexing from inside the system
219 *
220 * @param INT $dir_id
221 */
222 function SetDirID ( $dir_id )
223 {
224 $this->dir_id = $dir_id;
225 }
226
227 /**
228 * Set Directory Path :: Mainly used if re-indexing from inside the system
229 *
230 * @param INT $dir_id
231 */
232 function SetDirPath ( $dir_path )
233 {
234 $this->dir_path = $dir_path;
235 }
236
237 /**
238 * Set Storage Location path
239 *
240 * @param String $sl_path
241 */
242 function SetStorageLocationPath ( $sl_path )
243 {
244 $this->sl_path = $sl_path;
245 }
246
247 /**
248 * Set Storage Location name
249 *
250 * @param String $sl_path
251 */
252 function SetStorageLocationName ( $sl_name )
253 {
254 $this->sl_name = $sl_name;
255 }
256
257 /**
258 * Set Storage Location excluded folders
259 *
260 * @param String $sl_path
261 */
262 function SetStorageExcludedFolders ( $sl_excluded_folders )
263 {
264 if( strlen( trim( $sl_excluded_folders ) ) > 0 )
265 {
266 $this->sl_excluded_folders = explode( "\n", $sl_excluded_folders );
267 }
268 }
269
270 /**
271 * Get Log Folder Path
272 *
273 * @return String $this->log_folder_path
274 */
275 function GetLogFolderPath ()
276 {
277 return $this->log_folder_path;
278 }
279
280 /**
281 * Get Invalid Characters
282 *
283 * @return String $this->log_folder_path
284 */
285 function GetInvalidCharactersPath ()
286 {
287 return $this->invalid_characters_path;
288 }
289
290 /**
291 * Get Log File name
292 *
293 * @return String $this->log_file_name
294 */
295 function GetLogFileName ()
296 {
297 return $this->log_file_name;
298 }
299
300 /**
301 * Get quick or Long index
302 *
303 * @return String $this->quick_or_long_index
304 */
305 function GetQuickOrLongIndex ()
306 {
307 return $this->quick_or_long_index;
308 }
309
310 /**
311 * Get log date
312 *
313 * @return Date $this->log_date
314 */
315 function GetLogDate()
316 {
317 return $this->log_date;
318 }
319
320 /**
321 * Get time log
322 *
323 * @return Boolean $this->time_log;
324 */
325 function GetTimeLog ()
326 {
327 return $this->time_log;
328 }
329
330 /**
331 * Get usage type
332 *
333 * @return String $this->usage_type
334 */
335 function GetUsageType ()
336 {
337 return $this->usage_type;
338 }
339
340 /**
341 * Get display log flag
342 *
343 * @return Boolean
344 */
345 function GetDisplayLog ()
346 {
347 return $this->display_log;
348 }
349
350 /**
351 * Get name of unique file created by A7PRO
352 *
353 * @return String $this->unique_file_name
354 */
355 function GetUniqueFileName ()
356 {
357 return $this->unique_file_name;
358 }
359
360 /**
361 * Get Storage Location ID
362 *
363 * @return INT $this->sl_id
364 */
365 function GetStorageLocationID ()
366 {
367 return $this->sl_id;
368 }
369
370 /**
371 * Get Directory ID
372 *
373 * @return INT $this->dir_id
374 */
375 function GetDirID ()
376 {
377 return $this->dir_id;
378 }
379
380 /**
381 * Get Directory ID
382 *
383 * @return INT $this->dir_id
384 */
385 function GetDirPath ()
386 {
387 return $this->dir_path;
388 }
389
390 /**
391 * Get Storage Location path
392 *
393 * @return String $this->sl_path
394 */
395 function GetStorageLocationPath ()
396 {
397 return $this->sl_path;
398 }
399
400 /**
401 * Get Storage Location path
402 *
403 * @return String $this->sl_path
404 */
405 function GetStorageExcludedFolders ()
406 {
407 return $this->sl_excluded_folders;
408 }
409
410 /**
411 * Get Storage Location name
412 *
413 * @return String $this->sl_name
414 */
415 function GetStorageLocationName ()
416 {
417 return $this->sl_name;
418 }
419
420 /**
421 * Launch Initial indexing
422 *
423 * @return void
424 */
425 function InitialIndex ()
426 {
427 if( $this->GetDisplayLog() ) {
428 $log_string = $this->GetLogDate() . " Initial Indexing Launched";
429 PrintHelper::PrintToCMD( $log_string, 2 );
430 }
431
432 $this->StartInitialIndex();
433
434 if( $this->GetDisplayLog() ) {
435 $log_string = $this->GetLogDate() . " Initial Indexing Finished";
436 PrintHelper::PrintToCMD( $log_string, 2 );
437 }
438 }
439
440 /**
441 * (Index a storage location for the first time)
442 *
443 * ==> Retrieve all folders that require indexing (i.e: indexing flag to 1)
444 * ==> IF no records found break from the function
445 * ==> ELSE Retrieve all contents of all folders flagged for indexing to be used with existence check (i.e: Folder/file already inserted or not)
446 *
447 * ==>LOOP through the folders that require indexing and IntialMasterScan
448 *
449 * @return void
450 */
451 function StartInitialIndex ()
452 {
453 $this->check_folder_accessible = "";
454 $this->maintenance_type = "index_location";
455 $this->RetrieveFoldersFlaggedForIndexing();
456
457 if ( $this->fldrs_to_index_obj->count == 0 ) { // If no folder to be indexed break from the function
458 if( $this->GetDisplayLog() ) {
459 $log_string = " O Files/Folders found";
460 PrintHelper::PrintToCMD( $log_string, 2 );
461 }
462 return;
463 }
464
465 /** Build query condition to retrieve all contents from folders to be indexed */
466 $query_cond = $this->BuildGeneralQueryConditions( "fldrs_to_index_content" );
467
468 /** Retrieve contents of folders. This is to be used to check if a file/folder already exists or not. 0 means fetch by path */
469 $this->RetrieveFolderContents( $query_cond, 0 );
470
471 /** Start looping through required folders */
472 for ( $i = 0; $i < $this->fldrs_to_index_obj->count; $i++ )
473 {
474 $directory = DirectoryHelper::ConvertSLPathFromRelativeToFull( $this->fldrs_to_index_obj->data["sf_sf_path"][$i], $this->GetStorageLocationPath() ) . $this->fldrs_to_index_obj->data["sf_sf_name"][$i];
475
476 if( DirectoryHelper::CheckPathAccessible( $directory ) )
477 {
478 $this->InitialMasterScan( $this->fldrs_to_index_obj->data["sf_sf_id"][$i], $directory, $this->fldrs_to_index_obj->data["sf_sf_parent_id"][$i] );
479 }
480 else
481 {
482 //$this->SetIndexingError( $this->fldrs_to_index_obj->data["sf_sf_id"][$i], 7 );
483 $print_function = $this->GetOutputPrintFn();
484 $log_string = $this->GetLogDate() . " " . $directory . " is not accessible";
485
486 $maintenancelogs_obj = new MaintenanceLogsManager();
487 $maintenancelogs_obj->InsertLog(MaintenanceLogsManager::MM2_INDEX_LOCATION, $log_string);
488
489 $this->check_folder_accessible .= $log_string . "<br>";
490 $this->print_helper_obj->$print_function( $log_string, 2 );
491 }
492 }
493
494 unset( $this->fldrs_to_index_obj);
495 unset( $this->fldrs_content_obj);
496
497 /** When this check becomes dependant on the new folder flag, put the unsets directly after the for loop */
498 if ( $this->new_fldr_added ) { $this->StartInitialIndex(); }
499 }
500
501 /**
502 * Scan Directories. Used for initial indexing
503 *
504 * @param INT $dir_ID :: ID of directory we are currently in
505 * @param String $dir_name :: Directory we are currently in
506 */
507 function InitialMasterScan ( $dir_id, $directory, $parent_id )
508 {
509 global $tableCollab, $dateformat, $config;
510 $file_count = $file_size = $folder_count = 0; // Initialize counters
511
512 $print_function = $this->GetOutputPrintFn();
513
514 if( $this->GetDisplayLog() ) {
515 $log_string = $this->GetLogDate() . " Reading Directory '" . $directory . "'";
516 PrintHelper::PrintToCMD( $log_string, 2 );
517 }
518
519 /** If the directory ends with / REMOVE */
520 if ( substr( $directory, -1 ) == '/' ) { $directory = substr( $directory, 0, -1 ); }
521
522
523 if( !is_file( TextHelper::ConvertFromUTF8ToWIN1256($directory) . "/" . $this->GetUniqueFileName() ) )
524 {
525 $directory_win1256 = TextHelper::ConvertFromUTF8ToWIN1256($directory);
526
527 $tmp_storage_location_path = $this->GetStorageLocationPath();
528 if ( substr( $tmp_storage_location_path, -1 ) == '/' || substr( $tmp_storage_location_path, -1 ) == "\\") { $tmp_storage_location_path = substr( $tmp_storage_location_path, 0, -1 ); }
529
530
531 if( $config['create_a7pro2_files'] == 1 )
532 {
533 if( $this->GetDisplayLog() ) {
534 $log_string = "Creating " . $this->GetUniqueFileName() . " file for " . $directory;
535 $this->print_helper_obj->$print_function( $log_string, 1 );
536 }
537
538 // If this is the root dir
539 if( $tmp_storage_location_path == $directory )
540 {
541 $params_array['directory_base'] = $directory_win1256;
542 $params_array['directory_name'] = "";
543 }
544 else
545 {
546 $params_array['directory_base'] = TextHelper::ConvertFromUTF8ToWIN1256( dirname( $directory ) );
547 $params_array['directory_name'] = TextHelper::ConvertFromUTF8ToWIN1256( basename( $directory ) );
548 }
549
550 $params_array['directory'] = $directory_win1256;
551
552 $params_array['old_directory'] = "";
553 $params_array['old_directory_base_path'] = "";
554 $params_array['old_directory_name'] = "";
555
556 $params_array['directory_id'] = $dir_id;
557 $params_array['parent_id'] = $parent_id;
558 $build_res = $this->BuildUniqueFile( $params_array );
559
560 if ( $build_res === FALSE )
561 {
562 $log_string = "Error creating " . $this->GetUniqueFileName() . " file for " . $directory;
563 if( $this->GetDisplayLog() ) {
564 $this->print_helper_obj->$print_function( $log_string, 2 );
565 }
566 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
567 }
568 $build_res = null;
569 }
570
571 }
572
573 /** If directory couldn't be found */
574 if ( !$this->IsDirectory( $directory ) ) { $this->SetIndexingError( $dir_id ); return false; }
575
576 if( $config['operating_system'] == 'windows' )
577 {
578 /** If directory is not readable */
579 if ( !$this->IsDirectoryReadable( $directory ) ) { $this->SetIndexingError( $dir_id, 2 ); return false; }
580 }
581
582 /** Open directory to start reading */
583 $directory_list = opendir( TextHelper::ConvertFromUTF8ToWIN1256( $directory ) );
584
585 /** Set main query headers that will be used to insert directory content into DB */
586 $insert_content_query = "INSERT IGNORE INTO " . $tableCollab["system_files"] . "(sf_path, sf_name, sf_title, fk_sl_id, sf_type, sf_is_dir, sf_preview_base_source, sf_size, sf_inserting_date, sf_indexing_flag, sf_creation_date, sf_modification_date, sf_parent_id, sf_insert_from )";
587 $insert_content_query_count = 0;
588
589 /** Will indicate if at least one new folder has been added */
590 $new_fldr = false;
591
592 /** Start looping through directory content */
593 while ( FALSE !== ( $file = readdir( $directory_list )) )
594 {
595 $treat_as_file = false;
596
597 if( $file != '.' && $file != '..' )
598 {
599 /** Get file name and extension */
600 $file_name_info = FileHelper::NormalGetFileNameAndExtension ( TextHelper::ConvertFromWIN1256ToUTF8($file) );
601
602 $path = TextHelper::ConvertFromUTF8ToWIN1256( $directory ) . '/' . $file; // Build path of current fetched file/folder
603 //$path2 = $directory . '/' . $file; // Build path of current fetched file/folder
604
605 /** check if we want to treat a folder as a file */
606 if ( DirectoryHelper::TreatFolderAsFile( $file_name_info ) ) { $is_dir = false; $treat_as_file = true; }
607 else if( is_dir( $path ) ) { $is_dir = true; }
608 else { $is_dir = false; }
609
610 if( $is_dir )
611 {
612 /** If directory is rejected warn the user and CONTINUE to skip remaining logic and loop again ELSE add the folder count */
613 if ( $this->IsDirectoryRejected( TextHelper::ConvertFromWIN1256ToUTF8($file) ) )
614 {
615 if( $this->GetDisplayLog() ) {
616 $log_string = "Warning: Folder belongs to rejected list: " . $file;
617 PrintHelper::PrintToCMD( $log_string, 2 );
618 }
619 continue;
620 }
621 elseif( TextHelper::CheckForInvalidCharacters( TextHelper::ConvertFromWIN1256ToUTF8( $file ) ) )
622 {
623 $log_string = "Warning: Folder content invalid characters: " . $path;
624 PrintHelper::PrintToFile( $this->GetLogFolderPath() . $this->GetInvalidCharactersPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
625 continue;
626 }
627 else
628 {
629 $folder_count++; // Add folder count so it can be update later in the DB
630 }
631
632 /** If the folder is not already stored in the DB insert */
633 if( !$this->IsFileInDB( $directory, TextHelper::ConvertFromWIN1256ToUTF8( $file ) ) )
634 {
635 /** This will indicate that a new folder is to be added */
636 $new_fldr = true;
637
638 if( $this->GetDisplayLog() ) {
639 $log_string = "Registering Folder: " . $file;
640 PrintHelper::PrintToCMD( $log_string );
641 }
642
643 /** if $insert_content_query_count = 0, this the first query, set values else set ',' */
644 if( $insert_content_query_count == 0 ) { $insert_content_query .= "VALUES"; }
645 else { $insert_content_query .= ","; }
646
647 /** Set data for insertion */
648 $folder_dir_path = ( DirectoryHelper::ConvertSLPathFromFullToRelative( $directory, $this->GetStorageLocationPath() ) );
649 $folder_name = addslashes( TextHelper::ConvertFromWIN1256ToUTF8( $file ) );
650
651 /** Fill the batch query */
652 $insert_content_query .= " ('" . addslashes( $folder_dir_path ) . "','" . $folder_name . "', '', '" . $this->GetStorageLocationID() . "', '', 1, '', 0, NOW(), 1, NOW(), NOW(), " . $dir_id . ", 8)";
653
654 $insert_content_query_count++;
655
656 if( $this->GetDisplayLog() ) {
657 $log_string = "Folder Registered Successfully";
658 PrintHelper::PrintToCMD( $log_string, 2 );
659 }
660 }
661 }
662 else if ( is_file( $path ) || $treat_as_file )
663 {
664 /** Check if the file is rejected (i.e: starts with "." or its extension is in the rejected files list) */
665 if ( $this->IsFileRejected( TextHelper::ConvertFromWIN1256ToUTF8( $file ) ) || $this->IsFileInRejectedList( $file_name_info['extension'] ) )
666 {
667 if( $this->GetDisplayLog() ) {
668 $log_string = "Warning: File belongs to rejected list: " . $file;
669 PrintHelper::PrintToCMD( $log_string, 2 );
670 }
671 continue;
672 }
673 elseif ( TextHelper::CheckForInvalidCharacters( TextHelper::ConvertFromWIN1256ToUTF8( $file ) ) )
674 {
675 $log_string = "Warning: Folder content invalid characters: " . $path;
676 PrintHelper::PrintToFile( $this->GetLogFolderPath() . $this->GetInvalidCharactersPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
677 continue;
678 }
679 else
680 {
681 $file_count++;
682 if ( $treat_as_file ) {
683 $fldr_info = DirectoryHelper::GetDirectorySize( $path );
684 $current_file_size = $fldr_info['size'];
685 }
686 else
687 {
688 $current_file_size = filesize( $path );
689 }
690
691 $file_size += $current_file_size;
692 }
693
694 /** Sometimes we are not being able to retrieve file size so we need to set a default value */
695 if ( $current_file_size == "" ) {
696 $current_file_size = 0;
697 $log_string = "ERROR: File came with size empty in InitialMasterScan(): " . $path;
698 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
699 }
700
701 if( !$this->IsFileInDB( $directory, TextHelper::ConvertFromWIN1256ToUTF8( $file ) ) && $current_file_size > 0 )
702 {
703 if( $this->GetDisplayLog() ) {
704 $log_string = "Registering File: " . $file;
705 PrintHelper::PrintToCMD( $log_string );
706 }
707
708 /** if $insert_content_query_count = 0, this the first query, set values else set ',' */
709 if( $insert_content_query_count == 0 ) { $insert_content_query .= "VALUES"; }
710 else { $insert_content_query .= ","; }
711
712 /** Set data for insertion */
713 $file_dir_path = DirectoryHelper::ConvertSLPathFromFullToRelative( $directory, $this->GetStorageLocationPath() ) ;
714 $file_modified_date = date( $dateformat, filemtime( $path ) );
715 $file_creation_date = date( $dateformat, filectime( $path ) );
716
717 /** fill the batch query */
718 $insert_content_query .= " ('" . addslashes( $file_dir_path ) . "','" . addslashes( TextHelper::ConvertFromWIN1256ToUTF8( $file ) ) . "', '" . addslashes( $file_name_info['file_name'] ) . "', '" . $this->GetStorageLocationID() . "', '" . strtoupper( addslashes( $file_name_info['extension'] ) ) . "', 0, '" . $this->fldrs_to_index_obj->CreateFilePreviewBaseSrc() . "', '" . $current_file_size . "', NOW(), 0, '" . $file_creation_date . "', '" . $file_modified_date . "', " . $dir_id . ", 8)";
719
720 $insert_content_query_count++;
721
722 if( $this->GetDisplayLog() ) {
723 $log_string = "File Registered Successfully";
724 PrintHelper::PrintToCMD( $log_string, 2 );
725 }
726 }
727 }
728 }
729 }
730
731 if( $this->GetDisplayLog() ) {
732 $log_string = $this->GetLogDate() . " Finished Reading Directory '" . $directory . "'";
733 PrintHelper::PrintToCMD( $log_string, 2 );
734 }
735
736 /** If there is data to be inserted. ELSE if we are re-indexing from system issue the user a message that no files changed */
737 if( $insert_content_query_count > 0 )
738 {
739 /** insert the batch */
740 $res = AdvancedConnectSql( $insert_content_query );
741
742 if( $res['query_error'] == 1 )
743 {
744 $this->SetIndexingError( $dir_id, 2 );
745
746 if( $this->GetDisplayLog() ) {
747 $log_string = $this->GetLogDate() . " Error: Registering data for folder : '" . $directory . "' ( InitialMasterScan() )";
748 PrintHelper::PrintToCMD( $log_string, 2 );
749 }
750
751 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
752
753 /** Print query with error to log file */
754 $log_string = $insert_content_query;
755 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
756 }
757 else
758 {
759 /** If part of the result added had a new folder flag the class variable */
760 if ( $new_fldr ) { $this->new_fldr_added = true; }
761
762 if( $this->GetDisplayLog() ) {
763 $log_string = $this->GetLogDate() . " Folder data inserted successfully : " . $directory;
764 PrintHelper::PrintToCMD( $log_string, 2 );
765 }
766 }
767 }
768 elseif( $this->GetDirID() != 0 )
769 {
770 if( $this->GetDisplayLog() ) {
771 $log_string = $this->GetLogDate() . " 0 Files Changed";
772 PrintHelper::PrintToCMD( $log_string, 2 );
773 }
774 }
775
776 /** Set data to update folder parameters */
777 $params_array['file_size'] = $file_size;
778 $params_array['file_count'] = $file_count;
779 $params_array['folder_count'] = $folder_count;
780
781 if ( !$this->SetFolderParams( $dir_id, $params_array ) )
782 {
783 $this->SetIndexingError( $dir_id, 5 );
784
785 if( $this->GetDisplayLog() ) {
786 $log_string = "Error: Updating folder parameters " . $directory;
787 PrintHelper::PrintToCMD( $log_string, 2 );
788 }
789
790 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
791 }
792 }
793
794 /**
795 * (Launch Quick/Long indexing)
796 * ==> Flag all folders not flagged for deletion as 1
797 * ==> Start Long Index
798 *
799 * @return void
800 */
801 function QuickLongIndex ( $action )
802 {
803 $action_string = ( $action == "quick_index" ? "Quick" : "Long" );
804 $quick_or_long_index = ( $action == "quick_index" ? 9 : 10 );
805
806 $this->SetQuickOrLongIndex( $quick_or_long_index );
807
808 if ( $action == "long_index" )
809 {
810 if ( $this->GetDisplayLog() )
811 {
812// $log_string = "Attempting to flag folders for indexing";
813// //PrintHelper::PrintToCMD( $log_string, 2 );
814//
815// {// Logs
816// $log_message = '';
817// $text_log_message = '';
818// $screen_log_message = $log_string . "\n";
819//
820// $logs_params_array = array(
821// 'm_type' => ( $action == 'quick_index' ? MaintenanceLogsManager::MM1_QUICK_INDEX : MaintenanceLogsManager::MM3_LONG_INDEX ),
822// 'log_message' => $log_message,
823// 'text_log_message' => $text_log_message,
824// 'screen_log_message' => $screen_log_message
825// );
826// PrintHelper::ManageMaintenanceLogs($logs_params_array);
827// }
828 }
829
830 if ( !$this->FlagFoldersForIndexing () )
831 {
832 $log_string = "ERROR: Unable to flag folders for Long Indexing";
833
834 {// Logs
835 $log_message = $log_string;
836 $text_log_message = '';
837 $screen_log_message = $log_string . "\n";
838
839 $logs_params_array = array(
840 'm_type' => ( $action == 'quick_index' ? MaintenanceLogsManager::MM1_QUICK_INDEX : MaintenanceLogsManager::MM3_LONG_INDEX ),
841 'log_message' => $log_message,
842 'text_log_message' => $text_log_message,
843 'screen_log_message' => $screen_log_message
844 );
845 PrintHelper::ManageMaintenanceLogs($logs_params_array);
846 }
847 }
848 else
849 {
850 $log_string = "Folders successfully flagged for indexing";
851 }
852
853 if ( $this->GetDisplayLog() )
854 {
855 //PrintHelper::PrintToCMD( $log_string, 2 );
856
857 {// Logs
858 $log_message = $log_string;
859 $text_log_message = '';
860 $screen_log_message = $log_string . "\n";
861
862 $logs_params_array = array(
863 'm_type' => ( $action == 'quick_index' ? MaintenanceLogsManager::MM1_QUICK_INDEX : MaintenanceLogsManager::MM3_LONG_INDEX ),
864 'log_message' => $log_message,
865 'text_log_message' => $text_log_message,
866 'screen_log_message' => $screen_log_message
867 );
868 PrintHelper::ManageMaintenanceLogs($logs_params_array);
869 }
870 }
871
872 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
873 }
874
875 $this->DeleteManagement();
876
877 $this->StartQuickLongIndex();
878
879 }
880
881 /**
882 * (Initial Long Indexing)
883 *
884 * ==> Retrieve all folders that require indexing (i.e: indexing flag to 1)
885 * ==> IF no records found break from the function
886 * ==> ELSE LOOP through the folders that require indexing and LongQuickIndexScan
887 *
888 * @return void
889 */
890 function StartQuickLongIndex ( $recursive = true )
891 {
892 global $tableCollab;
893
894 $this->stop_quick_long_index = false;
895 $maintenance_run_obj = new MaintenanceRun();
896
897 $this->RetrieveFoldersFlaggedForIndexing();
898
899 if ( $this->fldrs_to_index_obj->count == 0 ) // If no folder to be indexed break from the function
900 {
901 return;
902 }
903
904 /** Start looping through required folders */
905 for ( $i = 0; $i < $this->fldrs_to_index_obj->count; $i++ )
906 {
907 if( $this->fldrs_to_index_obj->data["sf_sf_indexing_flag"][$i] != 1 || $this->fldrs_to_index_obj->data["sf_sf_is_dir"][$i] != 1 || $this->fldrs_to_index_obj->data["sf_sf_is_indexing_error"][$i] != 0 )
908 {
909 $maintenance_run_obj->DeleteIndexRun( $this->fldrs_to_index_obj->data["sf_sf_id"][$i] );
910 continue;
911 }
912
913 $directory = DirectoryHelper::ConvertSLPathFromRelativeToFull( $this->fldrs_to_index_obj->data["sf_sf_path"][$i], $this->GetStorageLocationPath() ) . $this->fldrs_to_index_obj->data["sf_sf_name"][$i];
914 $reset_dir_path = $this->fldrs_to_index_obj->data["sf_sf_path"][$i] . $this->fldrs_to_index_obj->data["sf_sf_name"][$i] . "/";
915
916 $array_data = array();
917 $array_data['dir_path'] = $this->fldrs_to_index_obj->data["sf_sf_path"][$i] . $this->fldrs_to_index_obj->data["sf_sf_name"][$i] . "/";
918 $array_data['sl_id'] = $this->fldrs_to_index_obj->data["sf_fk_sl_id"][$i];
919 $array_data['sf_id'] = $this->fldrs_to_index_obj->data["sf_sf_id"][$i];
920 $array_data['skip_inverse_check'] = 1;
921
922 $lock_state = FileHelper::CheckIfLockedFromAllDirections( $array_data );
923
924 if( $this->CheckIfInExcludedList( $reset_dir_path ) )
925 {
926 $this->SetIndexingError( $this->fldrs_to_index_obj->data["sf_sf_id"][$i], 8, $reset_dir_path );
927 }
928 elseif( $lock_state['success'] == 0 )
929 {
930 if ( !$this->SetFolderParams( $this->fldrs_to_index_obj->data["sf_sf_id"][$i], $params_array ) )
931 {
932 $this->SetIndexingError( $this->fldrs_to_index_obj->data["sf_sf_id"][$i], 5 );
933
934 if( $this->GetDisplayLog() ) {
935 $log_string = "Error: Updating folder parameters " . $directory;
936 PrintHelper::PrintToCMD( $log_string, 2 );
937 }
938
939 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
940 }
941
942
943 {// Logs
944 $log_message = $directory . " : " . $lock_state['msg'];
945 $text_log_message = '';
946 $screen_log_message = $directory . " : " . $lock_state['msg'] . "\n";
947
948 $logs_params_array = array(
949 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
950 'log_message' => $log_message,
951 'text_log_message' => $text_log_message,
952 'sf_id' => $this->fldrs_to_index_obj->data["sf_sf_id"][$i],
953 'sl_id' => $this->fldrs_to_index_obj->data["sf_fk_sl_id"][$i],
954 'sf_path' => $this->fldrs_to_index_obj->data["sf_sf_path"][$i],
955 'sf_name' => $this->fldrs_to_index_obj->data["sf_sf_name"][$i],
956 'screen_log_message' => $screen_log_message
957 );
958 PrintHelper::ManageMaintenanceLogs($logs_params_array);
959 }
960 }
961 elseif( DirectoryHelper::CheckPathAccessible( $directory ) )
962 {
963 $this->LongQuickIndexScan( $this->fldrs_to_index_obj->data["sf_sf_id"][$i], $directory, $this->fldrs_to_index_obj->data["sf_sf_parent_id"][$i] );
964 }
965 else
966 {
967 $this->FlagContentAsDeleted ( $this->fldrs_to_index_obj->data["sf_sf_id"][$i], $this->fldrs_to_index_obj->data["sf_sf_path"][$i], $this->fldrs_to_index_obj->data["sf_sf_name"][$i], $this->fldrs_to_index_obj->data["sf_sf_is_dir"][$i] );
968
969 $print_function = $this->GetOutputPrintFn();
970 $log_string = $this->GetLogDate() . " " . $directory . " is not accessible";
971 $this->check_folder_accessible .= $log_string . "<br>";
972 $this->print_helper_obj->$print_function( $log_string, 2 );
973 //$this->SetIndexingError( $this->fldrs_to_index_obj->data["sf_sf_id"][$i], 7 );
974
975 {// Logs
976 $log_message = $directory . " is not accessible" . "";
977 $text_log_message = '';
978 $screen_log_message = $directory . " is not accessible" . "\n";
979
980 $logs_params_array = array(
981 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
982 'log_message' => $log_message,
983 'text_log_message' => $text_log_message,
984 'sf_id' => $this->fldrs_to_index_obj->data["sf_sf_id"][$i],
985 'sl_id' => $this->fldrs_to_index_obj->data["sf_fk_sl_id"][$i],
986 'sf_path' => $this->fldrs_to_index_obj->data["sf_sf_path"][$i],
987 'sf_name' => $this->fldrs_to_index_obj->data["sf_sf_name"][$i],
988 'screen_log_message' => $screen_log_message
989 );
990 PrintHelper::ManageMaintenanceLogs($logs_params_array);
991 }
992 }
993
994 if( $this->stop_quick_long_index )
995 {
996 break;
997 }
998 }
999
1000 unset( $this->fldrs_to_index_obj );
1001
1002 if ( $this->new_fldr_added && $recursive ) { $this->StartQuickLongIndex(); }
1003 }
1004
1005 /**
1006 * Scan Based on Quick/Long index actions
1007 *
1008 * @param INT $dir_ID :: ID of directory we are currently in
1009 * @param String $dir_name :: Directory we are currently in
1010 */
1011 function LongQuickIndexScan ( $dir_id, $directory, $parent_id )
1012 {
1013 global $tableCollab, $dateformat, $config;
1014 $file_count = $file_size = $folder_count = 0; // Initialize counters
1015
1016 $this->fldrs_files_queries = null;
1017 unset( $this->fldrs_files_queries );
1018
1019 $print_function = $this->GetOutputPrintFn();
1020
1021 if( $this->GetDisplayLog() ) {
1022
1023 $log_string = $this->GetLogDate() . " Indexing Directory '" . $directory . "'";
1024 //$this->print_helper_obj->$print_function( $log_string, 2 );
1025
1026 {// Logs
1027 $log_message = '';
1028 $text_log_message = '';
1029 $screen_log_message = $log_string . "\n";
1030
1031 $logs_params_array = array(
1032 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
1033 'log_message' => $log_message,
1034 'text_log_message' => $text_log_message,
1035 'screen_log_message' => $screen_log_message
1036 );
1037 PrintHelper::ManageMaintenanceLogs($logs_params_array);
1038 }
1039 }
1040
1041 /** If the directory ends with '/' REMOVE */
1042 if ( substr( $directory, -1 ) == '/' ) { $directory = substr( $directory, 0, -1 ); }
1043
1044 // Generate unique file if it doesn't exist
1045 if( !is_file( TextHelper::ConvertFromUTF8ToWIN1256($directory) . "/" . $this->GetUniqueFileName() ) )
1046 {
1047 $directory_win1256 = TextHelper::ConvertFromUTF8ToWIN1256($directory);
1048
1049 $tmp_storage_location_path = $this->GetStorageLocationPath();
1050 if ( substr( $tmp_storage_location_path, -1 ) == '/' || substr( $tmp_storage_location_path, -1 ) == "\\") { $tmp_storage_location_path = substr( $tmp_storage_location_path, 0, -1 ); }
1051
1052 if( $config['create_a7pro2_files'] == 1 )
1053 {
1054 if( $this->GetDisplayLog() ) {
1055 $log_string = "Creating " . $this->GetUniqueFileName() . " file for " . $directory;
1056 $this->print_helper_obj->$print_function( $log_string, 1 );
1057 }
1058 // If this is the root dir
1059 if( $tmp_storage_location_path == $directory )
1060 {
1061 $params_array['directory_base'] = $directory_win1256;
1062 $params_array['directory_name'] = "";
1063 }
1064 else
1065 {
1066 $params_array['directory_base'] = TextHelper::ConvertFromUTF8ToWIN1256( dirname( $directory ) );
1067 $params_array['directory_name'] = TextHelper::ConvertFromUTF8ToWIN1256( basename( $directory ) );
1068 }
1069
1070 $params_array['directory'] = $directory_win1256;
1071
1072 $params_array['old_directory'] = "";
1073 $params_array['old_directory_base_path'] = "";
1074 $params_array['old_directory_name'] = "";
1075
1076 $params_array['directory_id'] = $dir_id;
1077 $params_array['parent_id'] = $parent_id;
1078 $build_res = $this->BuildUniqueFile( $params_array );
1079
1080 if ( $build_res === FALSE )
1081 {
1082 $log_string = "Error creating " . $this->GetUniqueFileName() . " file for " . $directory;
1083 if( $this->GetDisplayLog() ) {
1084 $this->print_helper_obj->$print_function( $log_string, 2 );
1085 }
1086 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
1087
1088 {// Logs
1089 $log_message = "Error creating " . $this->GetUniqueFileName() . " file for " . $directory;
1090 $text_log_message = '';
1091 $screen_log_message = "";
1092
1093 $logs_params_array = array(
1094 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
1095 'log_message' => $log_message,
1096 'text_log_message' => $text_log_message,
1097 'screen_log_message' => $screen_log_message
1098 );
1099 PrintHelper::ManageMaintenanceLogs($logs_params_array);
1100 }
1101 }
1102 $build_res = null;
1103 }
1104
1105 }
1106
1107 /**
1108 * Retrieve contents of the folder we are currently in
1109 * If 0 is returned then the folder didn't behave as a directory or not readable
1110 * In this case it means that it was deleted and no need to continue so return
1111 *
1112 * (N.B: The path returned doesn't contain an ending slash. Also the file/folder name is converted to UTF-8
1113 */
1114 if ( $this->ReadFolderContent( $directory ) == 0 )
1115 {
1116 $dir_relative_path = DirectoryHelper::ConvertSLPathFromFullToRelative( $directory, $this->GetStorageLocationPath() );
1117
1118 if ( !$this->FlagContentAsDeleted ( $dir_id, $dir_relative_path, "", 1 ) )
1119 {
1120 if( $this->GetDisplayLog() ) {
1121 $log_string = "Error: Flagging " . $directory . " to deleted (Ref: Main folder flagging)";
1122 $this->print_helper_obj->$print_function( $log_string, 2 );
1123 }
1124
1125 {// Logs
1126 $log_message = "Error: Flagging " . $directory . " to deleted (Ref: Main folder flagging)";
1127 $text_log_message = '';
1128 $screen_log_message = "";
1129
1130 $logs_params_array = array(
1131 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
1132 'log_message' => $log_message,
1133 'text_log_message' => $text_log_message,
1134 'screen_log_message' => $screen_log_message
1135 );
1136 PrintHelper::ManageMaintenanceLogs($logs_params_array);
1137 }
1138
1139 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
1140 }
1141 $dir_relative_path = null;
1142 return;
1143 }
1144
1145 /** Retrieve folder contents from DB. 1 means fetch using the parent ID */
1146 $this->RetrieveFolderContents( $dir_id, 1 );
1147
1148 /*
1149 if( $this->GetDisplayLog() ) {
1150 $log_string = $this->GetLogDate() . " Check started on DB content for '" . $directory . "'";
1151 $this->print_helper_obj->$print_function( $log_string, 2 );
1152 }
1153 */
1154
1155 /** If time log is flagged to true */
1156 if ( $this->GetTimeLog() && $this->GetDisplayLog() ) { $t_start = DateHelper::StartLoad(); }
1157
1158 /** Start looping on DB content */
1159 for ( $j = 0; $j < $this->fldrs_content_obj->count; $j++ )
1160 {
1161 $db_file_id = $this->fldrs_content_obj->data['sf_sf_id'][$j];
1162 $db_file_name = $this->fldrs_content_obj->data["sf_sf_name"][$j];
1163 $db_file_size = $this->fldrs_content_obj->data['sf_sf_size'][$j];
1164 $db_file_path = $this->fldrs_content_obj->data['sf_sf_path'][$j];
1165 $db_is_dir = $this->fldrs_content_obj->data['sf_sf_is_dir'][$j];
1166 $db_is_deleted = $this->fldrs_content_obj->data['sf_sf_indexing_flag'][$j];
1167 $db_sl_id = $this->fldrs_content_obj->data['sf_fk_sl_id'][$j];
1168 $db_file_preview_base_source = $this->fldrs_content_obj->data['sf_sf_preview_base_source'][$j];
1169
1170 /** This means this is the parent directory */
1171 if ( strlen( $db_file_name ) == 0 && $db_file_path == "./") { continue; }
1172
1173 /** if windows, compare DB data and physical files as case-insensitive. if linux case-sensitive */
1174 if( $config['operating_system'] == 'windows' && $config['enable_case_sensitive'] == 1 )
1175 {
1176 foreach ( $this->physical_fldr_content as $key => $value )
1177 {
1178 $text_lang = TextHelper::RetrieveTextLanguage( $key );
1179
1180 if( $text_lang == "en" )
1181 {
1182 $key_encoded = strtolower( $key );
1183 }
1184 else
1185 {
1186 $key_encoded = mb_strtolower( $key, 'UTF-8');
1187 }
1188
1189 $physical_fldr_content_to_check_if_file_exist[ $key_encoded ]['name'] = $key_encoded;
1190 }
1191
1192 $db_file_name_lang = TextHelper::RetrieveTextLanguage( $db_file_name );
1193
1194 if( $db_file_name_lang == "en" )
1195 {
1196 $db_file_name_encoded = strtolower( $key );
1197 }
1198 else
1199 {
1200 $db_file_name_encoded = mb_strtolower( $key, 'UTF-8');
1201 }
1202
1203 //$if_file_exist_physically = array_key_exists( mb_strtolower( $db_file_name, 'UTF-8'), array_change_key_case( $this->physical_fldr_content, CASE_LOWER ) );
1204 $if_file_exist_physically = isset( $physical_fldr_content_to_check_if_file_exist[ $db_file_name_encoded ]["name"] );
1205
1206 unset( $physical_fldr_content_to_check_if_file_exist );
1207 }
1208 else
1209 {
1210 $if_file_exist_physically = isset( $this->physical_fldr_content[ $db_file_name ]["name"] );
1211 }
1212
1213 /** If file exists physically */
1214 if ( $if_file_exist_physically )
1215 {
1216 // If file/folder was already flagged as deleted but for some reason it was returned back
1217 // before the records where deleted by the delete manager, reset the sf_indexing_flag
1218 if( $db_is_deleted == 2 )
1219 {
1220 if(!$this->ResetDeleteFlag( $db_file_id ) )
1221 {
1222 if( $this->GetDisplayLog() ) {
1223 $log_string = "Error: Resetting sf_indexing_flag from 2 to 0 for " . $db_file_path . $db_file_name . " ( DB Content :: QuickLongIndex() )";
1224 $this->print_helper_obj->$print_function( $log_string, 2 );
1225
1226 {// Logs
1227 $log_message = "Error: Resetting sf_indexing_flag from 2 to 0 for " . $db_file_path . $db_file_name . " ( DB Content :: QuickLongIndex() )";
1228 $text_log_message = '';
1229 $screen_log_message = "";
1230
1231 $logs_params_array = array(
1232 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
1233 'log_message' => $log_message,
1234 'text_log_message' => $text_log_message,
1235 'screen_log_message' => $screen_log_message
1236 );
1237 //PrintHelper::ManageMaintenanceLogs($logs_params_array);
1238 }
1239 }
1240 }
1241 }
1242
1243 if ( $db_is_dir)
1244 {
1245 $folder_count++;
1246 }
1247 else
1248 {
1249 $file_count++;
1250
1251 $modification_date = filemtime( $this->physical_fldr_content[ $db_file_name ]["path"] . "/" . $this->physical_fldr_content[ $db_file_name ]["name"] );
1252
1253 $update_query = "UPDATE " . $tableCollab["system_files"] . " SET sf_modification_date='" . date( "Y-m-d H:i:s", $modification_date ) . "' WHERE sf_id='" . $db_file_id . "'";
1254 $res = AdvancedConnectSql( $update_query );
1255
1256 $array_to_retrieve_size = array_change_key_case( $this->physical_fldr_content, CASE_LOWER );
1257
1258 $current_file_size = $array_to_retrieve_size[strtolower( $db_file_name ) ]["size"];
1259 $file_size += $current_file_size;
1260
1261 if ( $db_file_size != $current_file_size )
1262 {
1263 if( $this->GetDisplayLog() ) {
1264 $log_string = "\n" . "File has changed '" . $db_file_name . "'";
1265 $this->print_helper_obj->$print_function( $log_string, 2 );
1266 }
1267
1268 if ( !$this->RegenerateFileData( $db_file_id, $current_file_size ) )
1269 {
1270 if( $this->GetDisplayLog() ) {
1271 // Show sf_id
1272 $log_string = "Error: Resetting Generation flags for " . $db_file_path . $db_file_name . " ( DB Content :: QuickLongIndex() )";
1273 $this->print_helper_obj->$print_function( $log_string, 2 );
1274 }
1275
1276 {// Logs
1277 $log_message = "Error: Resetting Generation flags for " . $db_file_path . $db_file_name . " ( DB Content :: QuickLongIndex() )";
1278 $text_log_message = '';
1279 $screen_log_message = "";
1280
1281 $logs_params_array = array(
1282 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
1283 'log_message' => $log_message,
1284 'text_log_message' => $text_log_message,
1285 'screen_log_message' => $screen_log_message
1286 );
1287 PrintHelper::ManageMaintenanceLogs($logs_params_array);
1288 }
1289
1290 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
1291 }
1292 }
1293 }
1294 }
1295 else if ( $db_is_deleted != '2' ) // If file/folder doesn't exist, and not already flagged as to be deleted (sf_indexing_flag : 2)
1296 {
1297 /** Check if the file has row in Systemevent, in this case check if the action is rename and retrieve the old name and new name from log
1298 * so we dont need to delete this file and create another file, just rename this file */
1299 $check_file_renamed_info = array( 'sf_path' => $db_file_path, 'sf_name' => $db_file_name, 'sl_id' => $db_sl_id );
1300 $linux_watcher_obj = new LinuxWatcher();
1301 $if_file_renamed = $linux_watcher_obj->CheckIfFileRenamed( $check_file_renamed_info );
1302
1303 /** if the action is rename */
1304 if( $if_file_renamed['is_renamed'] )
1305 {
1306 if( $db_is_dir == 1 )
1307 {
1308 /** rename the folder */
1309 $tmp_update_system_files = "UPDATE " . $tableCollab["system_files"] . " SET sf_name = '" . $if_file_renamed['new_sf_name'] . "', sf_is_permissions_updated = 1";
1310 $tmp_update_system_files .= " WHERE sf_id = '" . $db_file_id . "'";
1311 $res = AdvancedConnectSql( $tmp_update_system_files );
1312
1313 /** change the path of the sub files/folders */
1314 $tmp_update_system_files = "UPDATE " . $tableCollab["system_files"] . " SET sf_path = REPLACE(sf_path, '" . $db_file_path . $db_file_name . "','" . $db_file_path . $if_file_renamed['new_sf_name'] . "')";
1315 $tmp_update_system_files .= " WHERE fk_sl_id = '" . $db_sl_id . "' AND sf_path LIKE '" . $db_file_path . $db_file_name . "%'";
1316 $res = AdvancedConnectSql( $tmp_update_system_files );
1317
1318 /** change the path of permissions */
1319 $update_permission_foldername = "UPDATE " . $tableCollab["folder_permissions"] . " SET fp_path = REPLACE(fp_path, '" . $db_file_path . $db_file_name . "','" . $db_file_path . $if_file_renamed['new_sf_name'] . "') WHERE fk_storage_locations_sl_id=" . $db_sl_id;
1320 $res = AdvancedConnectSql( $update_permission_foldername );
1321 }
1322 else
1323 {
1324 /** rename the file */
1325 $tmp_update_system_files = "UPDATE " . $tableCollab["system_files"] . " SET sf_name = '" . $if_file_renamed['new_sf_name'] . "', sf_title='" . $if_file_renamed['new_sf_name'] . "', sf_is_updated=1, sf_is_preview = 0, sf_preview_retries = 0, sf_is_text_extracted = 0, sf_is_exif_extracted = 0";
1326 $tmp_update_system_files .= " WHERE sf_id = '" . $db_file_id . "'";
1327 $res = AdvancedConnectSql( $tmp_update_system_files );
1328 }
1329 }
1330 else
1331 {
1332 if ( !$this->FlagContentAsDeleted ( $db_file_id, $db_file_path, $db_file_name, $db_is_dir ) )
1333 {
1334 if( $this->GetDisplayLog() ) {
1335 $log_string = "Error: Flagging " . $db_file_path . $db_file_name . " to deleted" . " ( DB Content :: QuickLongIndex() )";
1336 $this->print_helper_obj->$print_function( $log_string, 2 );
1337 }
1338
1339 {// Logs
1340 $log_message = "Error: Flagging " . $db_file_path . $db_file_name . " to deleted" . " ( DB Content :: QuickLongIndex() )";
1341 $text_log_message = '';
1342 $screen_log_message = "";
1343
1344 $logs_params_array = array(
1345 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
1346 'log_message' => $log_message,
1347 'text_log_message' => $text_log_message,
1348 'screen_log_message' => $screen_log_message
1349 );
1350 PrintHelper::ManageMaintenanceLogs($logs_params_array);
1351 }
1352
1353 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
1354 }
1355 }
1356 }
1357 }
1358
1359 /** If time log is flagged to true */
1360 if ( $this->GetTimeLog() && $this->GetDisplayLog() ) { $t_start = DateHelper::StartLoad(); }
1361
1362 /** Start looping on physical data content */
1363 foreach ( $this->physical_fldr_content AS $file )
1364 {
1365 $physical_file_name = $file['name'];
1366 $physical_file_path = $file['path'];// Doesn't contain an ending slash
1367 $physical_file_size = $file['size'];
1368
1369 $physical_is_dir = $file['dir'];
1370
1371 /** if windows, compare DB data and physical files as case-insensitive. if linux case-sensitive */
1372 if( $config['operating_system'] == 'windows' && $config['enable_case_sensitive'] == 1 )
1373 {
1374 $if_file_found_in_db = in_array( TextHelper::ConvertFromWIN1256ToUTF8( strtolower( $physical_file_name ) ), array_map('strtolower', $this->fldrs_content_obj->data["sf_sf_name"] ) );
1375 }
1376 else
1377 {
1378 $if_file_found_in_db = in_array( TextHelper::ConvertFromWIN1256ToUTF8($physical_file_name), $this->fldrs_content_obj->data["sf_sf_name"] );
1379 }
1380
1381 /** If the physical file/folder we are looping on is not found in DB content then its a new file/folder */
1382 if ( !$if_file_found_in_db )
1383 {
1384 $file_name_info = FileHelper::NormalGetFileNameAndExtension ( TextHelper::ConvertFromWIN1256ToUTF8($physical_file_name) );
1385
1386 // If it is a directory
1387 if ( $physical_is_dir && !$this->IsDirectoryRejected( TextHelper::ConvertFromWIN1256ToUTF8($physical_file_name) ) )
1388 {
1389 if( TextHelper::CheckForInvalidCharacters( TextHelper::ConvertFromWIN1256ToUTF8( $physical_file_name ) ) )
1390 {
1391 $log_string = "Warning: Folder contains invalid characters: " . $physical_file_path . "/" . $physical_file_name . "/";
1392 PrintHelper::PrintToFile( $this->GetLogFolderPath() . $this->GetInvalidCharactersPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
1393
1394 {// Logs
1395 $log_message = "Warning: Folder contains invalid characters: " . $physical_file_path . "/" . $physical_file_name . "/";
1396 $text_log_message = '';
1397 $screen_log_message = "";
1398
1399 $logs_params_array = array(
1400 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
1401 'log_message' => $log_message,
1402 'text_log_message' => $text_log_message,
1403 'screen_log_message' => $screen_log_message
1404 );
1405 PrintHelper::ManageMaintenanceLogs($logs_params_array);
1406 }
1407 continue;
1408 }
1409
1410 /** If unique file is not created. At this stage the IF and ELSE are the same
1411 * since we didn't use the concept of unique files till now
1412 */
1413 if ( !is_file( $physical_file_path . "/" . $physical_file_name . "/" . $this->GetUniqueFileName() ) )
1414 {
1415 $gen_unique_file = true;
1416 $indexing_flag = $this->GetNewFolderFlag();
1417 }
1418 else
1419 {
1420 $gen_unique_file = false;
1421 $indexing_flag = $this->GetNewFolderFlag();
1422 }
1423
1424 $this->new_fldr_added = true;
1425
1426 $params_array['directory'] = $physical_file_path . "/" . $physical_file_name;
1427
1428 {// Logs
1429 $log_message = "New folder detected : " . $physical_file_path . "/" . $physical_file_name;
1430 $text_log_message = '';
1431 $screen_log_message = "";
1432
1433 $logs_params_array = array(
1434 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
1435 'log_message' => $log_message,
1436 'text_log_message' => $text_log_message,
1437 'screen_log_message' => $screen_log_message
1438 );
1439 PrintHelper::ManageMaintenanceLogs($logs_params_array);
1440 }
1441
1442 // Check if the folder has been moved from another place. $file is an array containing folder info
1443 $check_res = $this->CheckIfMovedCopiedFolder( $file, $params_array['directory'], $dir_id );
1444
1445 if( $check_res['is_copied_moved'] )
1446 {
1447 $unique_file_data = $check_res['unique_file_data'];
1448
1449 // If the path stored in the unique file exists physically this means the folder was copied
1450 // Else it was moved
1451 if( is_dir( $unique_file_data['original_path'] ) )
1452 {
1453 if( $this->GetDisplayLog() ) {
1454 $log_string = "Folder was copied";
1455 $this->print_helper_obj->$print_function( $log_string, 2 );
1456 }
1457
1458 {// Logs
1459 $log_message = "Folder was copied : " . $params_array['directory'];
1460 $text_log_message = '';
1461 $screen_log_message = "";
1462
1463 $logs_params_array = array(
1464 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
1465 'log_message' => $log_message,
1466 'text_log_message' => $text_log_message,
1467 'screen_log_message' => $screen_log_message
1468 );
1469 PrintHelper::ManageMaintenanceLogs($logs_params_array);
1470 }
1471
1472 if( $config['create_a7pro2_files'] == 1 )
1473 {
1474 $params_array['directory'] = $physical_file_path . "/" . $physical_file_name;
1475 $params_array['directory_base'] = $physical_file_path;
1476 $params_array['directory_name'] = $physical_file_name;
1477
1478 $params_array['old_directory'] = "";
1479 $params_array['old_directory_base_path'] = "";
1480 $params_array['old_directory_name'] = "";
1481
1482 $params_array['directory_id'] = $res['last_id'];//wrong value, cannot find
1483 $params_array['parent_id'] = $dir_id;
1484 $build_res = $this->BuildUniqueFile( $params_array );
1485 }
1486
1487 if ( $build_res === FALSE )
1488 {
1489 $log_string = "Error: Updating " . $this->GetUniqueFileName() . " file for copied folder";
1490 if( $this->GetDisplayLog() ) {
1491 $this->print_helper_obj->$print_function( $log_string, 2 );
1492 }
1493 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
1494 }
1495 $build_res = null;
1496
1497 }
1498 else // If moved
1499 {
1500 if( $this->GetDisplayLog() ) {
1501 $log_string = "Folder was moved";
1502 $this->print_helper_obj->$print_function( $log_string, 2 );
1503 }
1504
1505 $manage_fldrs_params_array = array();
1506 $manage_fldrs_params_array['directory_tmp'] = $physical_file_path . "/" . $physical_file_name . "/";
1507 $manage_fldrs_params_array['directory_base_tmp'] = $physical_file_path . "/";
1508 $manage_fldrs_params_array['directory_name_tmp'] = $physical_file_name;
1509
1510 $manage_fldrs_params_array['old_directory_tmp'] = $unique_file_data['original_path'];
1511 $manage_fldrs_params_array['old_directory_base_path_tmp'] = $unique_file_data['dir_base'];
1512 $manage_fldrs_params_array['old_directory_name_tmp'] = $unique_file_data['directory_name'];
1513
1514 $manage_fldrs_params_array['parent_dir'] = $dir_id;
1515
1516 // Update moved folder data in DB
1517 $move_folders_res = $this->ManageMovedFolders( $manage_fldrs_params_array );
1518
1519 if ( !$move_folders_res['error'] )
1520 {
1521 if( $config['create_a7pro2_files'] == 1 )
1522 {
1523 $params_array['directory'] = $physical_file_path . "/" . $physical_file_name;
1524 $params_array['directory_base'] = $physical_file_path;
1525 $params_array['directory_name'] = $physical_file_name;
1526
1527 $params_array['old_directory'] = $unique_file_data['original_path'];
1528 $params_array['old_directory_base_path'] = $unique_file_data['dir_base'];
1529 $params_array['old_directory_name'] = $unique_file_data['directory_name'];
1530
1531 $params_array['directory_id'] = $res['last_id'];
1532 $params_array['parent_id'] = $dir_id;
1533
1534 $build_res = $this->BuildUniqueFile( $params_array );
1535 }
1536
1537 if ( $build_res === FALSE )
1538 {
1539 $log_string = "Error: Updating " . $this->GetUniqueFileName() . " file for moved folder";
1540 if( $this->GetDisplayLog() ) {
1541 $this->print_helper_obj->$print_function( $log_string, 2 );
1542 }
1543 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
1544 }
1545 $build_res = null;
1546 }
1547 else
1548 {
1549 // If an error occurred
1550 if( $this->GetDisplayLog() ) {
1551 $log_string = $move_folders_res['error_msg'];
1552 $this->print_helper_obj->$print_function( $log_string, 2 );
1553 }
1554 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
1555 }
1556
1557 }
1558 }
1559
1560 // If the system didn't go into the logic of moving folders or it did but the folder was considered as new
1561 if ( !isset($move_folders_res) || $move_folders_res['consider_as_new'] )
1562 {
1563 /*
1564 if( $this->GetDisplayLog() ) {
1565 $log_string = $physical_file_name . " is a new folder";
1566 $this->print_helper_obj->$print_function( $log_string, 2 );
1567 }
1568 */
1569
1570 $res = $this->PrepareFileFolderInsertion( $file, $dir_id, $file_count, $file_size, $folder_count, $indexing_flag );
1571 }
1572 else
1573 {
1574 if( !$move_folders_res['error'] ) { $folder_count++; }
1575 }
1576 }
1577 else if ( !$this->IsFileRejected( TextHelper::ConvertFromWIN1256ToUTF8($physical_file_name) ) && !$this->IsFileInRejectedList( $file_name_info['extension'] ) )
1578 {
1579 if( TextHelper::CheckForInvalidCharacters( TextHelper::ConvertFromWIN1256ToUTF8( $physical_file_name ) ) )
1580 {
1581 $log_string = "Warning: File name contains invalid characters: " . $physical_file_path . "/" . $physical_file_name;
1582 PrintHelper::PrintToFile( $this->GetLogFolderPath() . $this->GetInvalidCharactersPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
1583
1584 {// Logs
1585 $log_message = "Warning: File name contains invalid characters: " . $physical_file_path . "/" . $physical_file_name;
1586 $text_log_message = '';
1587 $screen_log_message = "";
1588
1589 $logs_params_array = array(
1590 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
1591 'log_message' => $log_message,
1592 'text_log_message' => $text_log_message,
1593 'screen_log_message' => $screen_log_message
1594 );
1595 PrintHelper::ManageMaintenanceLogs($logs_params_array);
1596 }
1597
1598 continue;
1599 }
1600
1601 {// Logs
1602 $log_message = "New file detected : " . $physical_file_path . "/" . $physical_file_name;
1603 $text_log_message = '';
1604 $screen_log_message = "";
1605
1606 $logs_params_array = array(
1607 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
1608 'log_message' => $log_message,
1609 'text_log_message' => $text_log_message,
1610 'screen_log_message' => $screen_log_message
1611 );
1612 PrintHelper::ManageMaintenanceLogs($logs_params_array);
1613 }
1614
1615 $indexing_flag = 0;
1616
1617 $this->PrepareFileFolderInsertion( $file, $dir_id, $file_count, $file_size, $folder_count, $indexing_flag );
1618 }
1619 }
1620 }
1621
1622 /** Insert prepared query values from PrepareFileFolderInsertion() holding files and folders into DB as a batch */
1623 if ( !$this->InsertFileFolderToDB() )
1624 {
1625 $this->SetIndexingError( $dir_id, 4 );
1626 }
1627
1628 if ( $this->GetTimeLog() && $this->GetDisplayLog() ) {
1629 $t_total_time = round( ( DateHelper::FinishLoad() - $t_start), 6 );
1630
1631 $log_string = "<span class='error errorBorder'>Physical Content Check Finished in " . $t_total_time . " Seconds </span>";
1632 $this->print_helper_obj->$print_function( $log_string, 2 );
1633 }
1634
1635 /** Set data to update folder parameters */
1636 $params_array['file_size'] = $file_size;
1637 $params_array['file_count'] = $file_count;
1638 $params_array['folder_count'] = $folder_count;
1639
1640 /** Set required folder params ELSE delete flagged content if any */
1641 if ( !$this->SetFolderParams( $dir_id, $params_array ) )
1642 {
1643 $this->SetIndexingError( $dir_id, 5 );
1644
1645 if( $this->GetDisplayLog() ) {
1646 $log_string = "Error: Updating folder parameters " . $directory . " ( LongQuickIndexScan() )";
1647 $this->print_helper_obj->$print_function( $log_string, 2 );
1648
1649 {// Logs
1650 $log_message = "Error: Updating folder parameters " . $directory . " ( LongQuickIndexScan() )";
1651 $text_log_message = '';
1652 $screen_log_message = "";
1653
1654 $logs_params_array = array(
1655 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
1656 'log_message' => $log_message,
1657 'text_log_message' => $text_log_message,
1658 'screen_log_message' => $screen_log_message
1659 );
1660 PrintHelper::ManageMaintenanceLogs($logs_params_array);
1661 }
1662 }
1663
1664 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
1665 }
1666 else
1667 {
1668 $this->DeleteManagement();
1669 }
1670
1671
1672 if( $this->GetDisplayLog() ) {
1673 //$log_string = $this->GetLogDate() . " Finished Indexing Directory '" . $directory . "'";
1674 $log_string = "Finished;";
1675 //$this->print_helper_obj->$print_function( $log_string, 2 );
1676
1677 {// Logs
1678 $log_message = '';
1679 $text_log_message = '';
1680 $screen_log_message = $log_string . "\n";
1681
1682 $logs_params_array = array(
1683 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
1684 'log_message' => $log_message,
1685 'text_log_message' => $text_log_message,
1686 'screen_log_message' => $screen_log_message
1687 );
1688 PrintHelper::ManageMaintenanceLogs($logs_params_array);
1689 }
1690 }
1691
1692
1693 }
1694
1695 /**
1696 * Retrieve last .a7pr path generated
1697 *
1698 * @param string $full_path
1699 * @return string
1700 */
1701 public static function RetrieveLastUniqueFileGenerated( $full_path )
1702 {
1703 $full_path_temp = $full_path;
1704 $i = 1;
1705
1706 while( true )
1707 {
1708 if( is_file( $full_path . "-" . $i ) )
1709 {
1710 $full_path_temp = $full_path . "-" . $i;
1711 $i++;
1712 }
1713 else
1714 {
1715 break;
1716 }
1717 }
1718
1719 $return_data = array( "current_file" => $full_path_temp, "next_file" => $full_path . "-" . $i );
1720
1721 return $return_data;
1722 }
1723
1724 /**
1725 * Detects if a folders has been moved from one directory to another
1726 *
1727 * @param String $unique_file_path :: C:/A/B/FLDR1
1728 * @param Array $folder_info :: Contains information about the folder to detect
1729 * ex:
1730 * $folder_info['name'] = FLDR1 (Encoding: WINDOWS-1256)
1731 * $folder_info['dir'] = 0/1 :: In this case it will always be 1
1732 * $folder_info['size'] = null
1733 * $folder_info['path'] = C:/A/B :: Note that there is no ending slash in the path (Encoding: WINDOWS-1256)
1734 */
1735 function CheckIfMovedCopiedFolder( &$folder_info, $unique_file_path, $dir_id )
1736 {
1737 global $config;
1738
1739 if( $config['create_a7pro2_files'] == 0 )
1740 {
1741 $res['is_copied_moved'] = false;
1742 return $res;
1743 }
1744
1745 $res['is_copied_moved'] = null;
1746
1747 $unique_file = $unique_file_path . "/" . $this->GetUniqueFileName();
1748
1749 $unique_file_result = self::RetrieveLastUniqueFileGenerated( $unique_file );
1750 $unique_file = $unique_file_result['current_file'];
1751
1752 $unique_file_data = $this->ParseUniqueFile( $unique_file );
1753
1754 if(strlen(trim( $unique_file_data['parent_id'] ) ) > 0 )
1755 {
1756 $res['unique_file_data'] = $this->RetrieveDirPathFromID( $unique_file_data['parent_id'], $unique_file_data['directory_name'] );
1757
1758 if( $dir_id == $unique_file_data['parent_id'] )
1759 {
1760 $res['is_copied_moved'] = false;
1761 }
1762 else
1763 {
1764 $res['is_copied_moved'] = true;
1765 }
1766 }
1767 else
1768 {
1769 $folder_base_path = $folder_info['path'];
1770 $folder_base_path = TextHelper::ConvertSingleBackslashesToForwardslashes( $folder_base_path );
1771 $directory_path = $folder_base_path . "/" . $folder_info['name'] . "/";
1772
1773 $unique_file_data['original_path'] = $unique_file_data['path'];
1774 $unique_file_data['path_converted'] = TextHelper::ConvertSingleBackslashesToForwardslashes( $unique_file_data['path'] );
1775
1776 $res['unique_file_data'] = $unique_file_data;
1777
1778 if( $unique_file_data['path_converted'] == $directory_path )
1779 {
1780 $res['is_copied_moved'] = false;
1781 }
1782 else
1783 {
1784 $res['is_copied_moved'] = true;
1785 }
1786 }
1787
1788 return $res;
1789 }
1790
1791 /**
1792 * Parse .a7pro xml
1793 *
1794 * @param Strinf $unique_file_path
1795 * @return Array
1796 */
1797 function ParseUniqueFile( $unique_file_path )
1798 {
1799 $unique_file_data = array();
1800
1801 $xml_parser = simplexml_load_file( $unique_file_path );
1802
1803 $unique_file_data['path'] = (string)$xml_parser->dir_path;
1804 $unique_file_data['dir_base'] = (string)$xml_parser->dir_base;
1805 $unique_file_data['directory_name'] = (string)$xml_parser->directory_name;
1806
1807 $unique_file_data['old_path'] = (string)$xml_parser->old_dir_path;
1808 $unique_file_data['old_dir_base'] = (string)$xml_parser->old_directory_base_path;
1809 $unique_file_data['old_directory_name'] = (string)$xml_parser->old_directory_name;
1810
1811 $unique_file_data['dir_id'] = (string)$xml_parser->dir_id;
1812 $unique_file_data['parent_id'] = (string)$xml_parser->parent_id;
1813
1814 return $unique_file_data;
1815 }
1816
1817 /**
1818 * Manage Moved folders
1819 *
1820 * @param Array $params_array
1821 * @example $params_array Array Structure:
1822 * $params_array['old_directory_tmp'] :: Old path of the folder (C:/A/B/C/)
1823 * $params_array['old_directory_base_path_tmp'] :: Old base of the folder (C:/A/B/)
1824 * $params_array['old_directory_name_tmp'] :: Old name of the folder (C)
1825 * $params_array['directory_tmp'] :: New/Current path of the folder (C:/1/2/C/)
1826 * $params_array['directory_base_tmp'] :: New/Current base path of the folder (C:/1/2/)
1827 * $params_array['directory_name_tmp'] :: New/Current base path of the folder (2)
1828 * $params_array['parent_dir'] :: Parent directory of the folder we are moving
1829 *
1830 */
1831 function ManageMovedFolders( $params_array )
1832 {
1833 global $tableCollab, $config;
1834 $fn_res = array();
1835 $db_res_1 = "";
1836 $db_res_2 = "";
1837
1838 if( $config['create_a7pro2_files'] == 0 )
1839 {
1840 $fn_res['error'] = true;
1841 $fn_res['error_msg'] = ".a7pro file does not exist";
1842 }
1843
1844// $old_directory_path = TextHelper::ConvertFromWIN1256ToUTF8( $params_array['old_directory_tmp'] );
1845// $old_directory_relative_path = $old_directory_path;
1846// $old_directory_base_relative_path = TextHelper::ConvertFromWIN1256ToUTF8( $params_array['old_directory_base_path_tmp'] );
1847// $old_directory_name = TextHelper::ConvertFromWIN1256ToUTF8( $params_array['old_directory_name_tmp'] );
1848
1849 $old_directory_path = ( $params_array['old_directory_tmp'] );
1850 $old_directory_relative_path = $old_directory_path;
1851 $old_directory_base_relative_path =( $params_array['old_directory_base_path_tmp'] );
1852 $old_directory_name = ( $params_array['old_directory_name_tmp'] );
1853
1854 $directory_relative_path = TextHelper::ConvertFromWIN1256ToUTF8( $params_array['directory_tmp'] );
1855 $directory_base_relative_path = TextHelper::ConvertFromWIN1256ToUTF8( $params_array['directory_base_tmp'] );
1856 $directory_name = TextHelper::ConvertFromWIN1256ToUTF8( $params_array['directory_name_tmp'] );
1857
1858
1859 // Get information of storage location where the file was orginally
1860 {
1861 $sl_info = StorageLocationHelper::RetrieveStorageLocationIDFromPath( $old_directory_path );
1862 $old_sl_id = $sl_info['sl_id'];
1863 $old_sl_path = $sl_info['sl_path'];
1864 }
1865
1866
1867 $old_directory_relative_path = DirectoryHelper::ConvertSLPathFromFullToRelative( $old_directory_relative_path, $old_sl_path, false );
1868 $old_directory_base_relative_path = DirectoryHelper::ConvertSLPathFromFullToRelative( $old_directory_base_relative_path, $old_sl_path, false );
1869
1870 $directory_relative_path = DirectoryHelper::ConvertSLPathFromFullToRelative( $directory_relative_path, $this->GetStorageLocationPath(), false );
1871 $directory_base_relative_path = DirectoryHelper::ConvertSLPathFromFullToRelative( $directory_base_relative_path, $this->GetStorageLocationPath(), false );
1872
1873
1874 $parent_id = $params_array['parent_dir'];
1875
1876 $db_begin_res = AdvancedConnectSql( "BEGIN;" );
1877
1878 if( $db_begin_res['query_error'] == 1 )
1879 {
1880 $fn_res['error'] = true;
1881 $fn_res['error_msg'] = "Couldn't initialize BEGIN/ROLLBACK queries (ManageMovedFolders())";
1882
1883 $db_begin_res = null;
1884 unset( $db_begin_res );
1885
1886 return $fn_res;
1887 }
1888
1889 if(strlen( $directory_base_relative_path ) > 0 && strlen( $directory_name ) > 0 && is_numeric( $parent_id ) && is_numeric( $old_sl_id ) && strlen( $old_directory_name ) > 0 && strlen( $old_directory_base_relative_path ) > 0 )
1890 {
1891 // Update the main record of the folder we are moving
1892 $qry_update = "UPDATE " . $tableCollab['system_files'] . " SET sf_path='" . addslashes($directory_base_relative_path) . "', sf_name='" . addslashes($directory_name) . "', sf_indexing_flag=1, sf_parent_id='" . $parent_id . "', fk_sl_id='" . $this->GetStorageLocationID() . "' WHERE sf_path='" . addslashes($old_directory_base_relative_path) . "' AND sf_name='" . addslashes($old_directory_name) . "' AND fk_sl_id='" . $old_sl_id . "'";
1893 $db_res_1 = AdvancedConnectSql($qry_update);
1894
1895 if( $db_res_1['query_error'] == 1 )
1896 {
1897 $fn_res['error'] = true;
1898 $fn_res['error_msg'] = "An error occurred while trying to update moved folder DB records ( REF1: ManageMovedFolders())";
1899
1900 {// Logs
1901 $log_message = "An error occurred while trying to update moved folder DB records ( REF1: ManageMovedFolders()) : " . $old_directory_relative_path;
1902 $text_log_message = '';
1903 $screen_log_message = "";
1904
1905 $logs_params_array = array(
1906 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
1907 'log_message' => $log_message,
1908 'text_log_message' => $text_log_message,
1909 'screen_log_message' => $screen_log_message
1910 );
1911 PrintHelper::ManageMaintenanceLogs($logs_params_array);
1912 }
1913
1914 $db_res_1 = null;
1915 unset( $db_res_1 );
1916
1917 return $fn_res;
1918 }
1919 else
1920 {
1921 // Update info of the subfolders/files of the moved directory
1922 $qry_update = "UPDATE " . $tableCollab['system_files'] . " SET sf_path=REPLACE(sf_path, '" . addslashes($old_directory_relative_path) . "', '" . addslashes($directory_relative_path) . "'), sf_indexing_flag=1, fk_sl_id='" . $this->GetStorageLocationID() . "' WHERE sf_path LIKE '" . addslashes($old_directory_relative_path) . "%' AND fk_sl_id='" . $old_sl_id . "'";
1923 $db_res_2 = AdvancedConnectSql($qry_update);
1924
1925 if( $db_res_2['query_error'] == 1 )
1926 {
1927 $db_rollback_res = AdvancedConnectSql( "ROLLBACK;" );
1928
1929 if( $db_rollback_res['query_error'] == 1 )
1930 {
1931 $fn_res['error'] = true;
1932 $fn_res['error_msg'] = "Couldn't ROLLBACK queries (ManageMovedFolders())";
1933
1934 $db_rollback_res = null;
1935 unset( $db_rollback_res );
1936 }
1937
1938 $fn_res['error'] = true;
1939 $fn_res['error_msg'] .= "\n\n" . "An error occurred while trying to update DB records of subfolders/files of the moved folder (REF2: ManageMovedFolders())";
1940
1941 {// Logs
1942 $log_message = "An error occurred while trying to update DB records of subfolders/files of the moved folder (REF2: ManageMovedFolders()) : " . $old_directory_relative_path;
1943 $text_log_message = '';
1944 $screen_log_message = "";
1945
1946 $logs_params_array = array(
1947 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
1948 'log_message' => $log_message,
1949 'text_log_message' => $text_log_message,
1950 'screen_log_message' => $screen_log_message
1951 );
1952 PrintHelper::ManageMaintenanceLogs($logs_params_array);
1953 }
1954
1955 return $fn_res;
1956 }
1957 else
1958 {
1959 $db_begin_res = AdvancedConnectSql( "COMMIT;" );
1960
1961 if( $db_res_1['affected_rows'] == 0 && $db_res_2['affected_rows'] == 0 )
1962 {
1963 $fn_res['error'] = false;
1964 $fn_res['consider_as_new'] = true;
1965 }
1966 else
1967 {
1968 $fn_res['error'] = false;
1969 $fn_res['consider_as_new'] = false;
1970 }
1971
1972 $this->stop_quick_long_index = true;
1973
1974 return $fn_res;
1975 }
1976 }
1977 }
1978 else
1979 {
1980 $fn_res['error'] = true;
1981 $fn_res['error_msg'] = ".a7pro file does not contais correct data";
1982 }
1983 }
1984
1985
1986 /**
1987 * Check the Files and Folders Flagged 2 to delete
1988 *
1989 */
1990 function DeleteManagement()
1991 {
1992 $print_function = $this->GetOutputPrintFn();
1993
1994 if ( !$this->DeleteFlaggedContent() )
1995 {
1996
1997
1998 if( $this->GetDisplayLog() ) {
1999 $log_string = "Error: Deleting records";
2000 $this->print_helper_obj->$print_function( $log_string, 2 );
2001 }
2002
2003 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
2004 }
2005 }
2006
2007 /**
2008 * Reset sf_indexing_flag from 2 to 0
2009 *
2010 * @param INT $db_id :: File folder we are currently checking
2011 */
2012 function ResetDeleteFlag( $db_id )
2013 {
2014 global $tableCollab;
2015
2016 $update_query = "UPDATE " . $tableCollab["system_files"] . " SET sf_indexing_flag=1, sf_flagged_as_deleted_date='0000-00-00 00:00:00' WHERE sf_id='" . $db_id . "'";
2017 $res = AdvancedConnectSql( $update_query );
2018
2019 if ( $res['query_error'] == 1 )
2020 {
2021 $log_string = "Failed to reset sf_indexing_flag from 2 to 0: " . $update_query;
2022 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
2023
2024 {// Logs
2025 $log_message = "Failed to reset sf_indexing_flag from 2 to 0: id : " . $db_id;
2026 $text_log_message = '';
2027 $screen_log_message = "";
2028
2029 $logs_params_array = array(
2030 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
2031 'log_message' => $log_message,
2032 'text_log_message' => $text_log_message,
2033 'screen_log_message' => $screen_log_message
2034 );
2035 //PrintHelper::ManageMaintenanceLogs($logs_params_array);
2036 }
2037
2038 $action_res = false;
2039 }
2040 else
2041 {
2042 $tmp_update_files = "UPDATE " . $tableCollab["system_files"] . " SET sf_is_triggers_detected=0, sf_inserting_date= NOW() WHERE sf_id='" . $db_id . "'";
2043 $res = AdvancedConnectSql( $tmp_update_files );
2044
2045 $action_res = true;
2046 }
2047
2048 $update_query = null;
2049 unset( $update_query);
2050
2051 $res = null;
2052 unset( $res);
2053
2054 $log_string = null;
2055 unset( $log_string );
2056
2057 return $action_res;
2058 }
2059
2060 /**
2061 * Delete flagged content data and DB records
2062 *
2063 * @return boolean
2064 */
2065 function DeleteFlaggedContent ()
2066 {
2067 global $tableCollab, $config;
2068 $success = 1;
2069
2070 $content_del = $this->RetrieveContentFlaggedAsDeleted();
2071
2072 /** If there is data to be deleted */
2073 if ( $content_del->count > 0 )
2074 {
2075 /** Delete all files */
2076 for ( $s = 0; $s < $content_del->count; $s++ )
2077 {
2078 if( $content_del->data["sf_sf_is_dir"][$s] == 0 )
2079 {
2080 $file_info = array();
2081 $file_info['preview_base_source'] = $content_del->data['sf_sf_preview_base_source'][$s];
2082 $file_info['file_id'] = $content_del->data["sf_sf_id"][$s];
2083 $file_info['file_name'] = $content_del->data["sf_sf_name"][$s];
2084 $file_info['file_name_win1256'] = TextHelper::ConvertFromUTF8ToWIN1256($content_del->data["sf_sf_name"][$s]);
2085 $file_info['file_path'] = $content_del->data["sf_sf_path"][$s];
2086 $file_info['file_path_win1256'] = TextHelper::ConvertFromUTF8ToWIN1256($content_del->data["sf_sf_path"][$s]);
2087 $file_info['file_type'] = $content_del->data["sf_sf_type"][$s];
2088 $file_info['file_parent_id'] = $content_del->data["sf_sf_parent_id"][$s];
2089 $file_info['full_preview_files_paths'] = addslashes( $config['dam_path'] . PREVIEW_FILES_PATHS );
2090 $file_info['sl_path'] = $this->GetStorageLocationPath();
2091 $file_info['sl_id'] = $content_del->data['sf_fk_sl_id'][$s];
2092 $file_info['flg_deleted_on'] = $content_del->data['sf_sf_flagged_as_deleted_date'][$s];
2093
2094 if( ShouldActivateDelete($file_info) )
2095 {
2096 $delete_msg = "Deleting File " . $content_del->data["sf_sf_name"][$s] . " : ";
2097 $error_msg = DeleteFileFromDB( $file_info );
2098
2099 if( strlen( trim( $error_msg ) ) == 0 )
2100 {
2101 $delete_msg .= "Resources File Deleted Successfully";
2102 }
2103 else
2104 {
2105 $this->SetIndexingError( $content_del->data["sf_sf_id"][$s], 6 );
2106 $success = 0;
2107 $delete_msg .= $error_msg;
2108 }
2109
2110 if( $this->GetDisplayLog() ) { PrintHelper::PrintToCMD( $delete_msg, 2 ); }
2111 unset($file_info);
2112 }
2113 else
2114 {
2115 if(!$this->ResetDeleteFlag( $content_del->data["sf_sf_id"][$s] ) )
2116 {
2117 if( $this->GetDisplayLog() ) {
2118 $log_string = "Error: Resetting sf_indexing_flag from 2 to 0 for " . $content_del->data["sf_sf_path"][$s] . $content_del->data["sf_sf_name"][$s] . " ( DB Content :: QuickLongIndex() )";
2119 $this->print_helper_obj->PrintToCMD( $log_string, 2 );
2120
2121 {// Logs
2122 $log_message = $log_string;
2123 $text_log_message = '';
2124 $screen_log_message = "";
2125
2126 $logs_params_array = array(
2127 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
2128 'log_message' => $log_message,
2129 'text_log_message' => $text_log_message,
2130 'screen_log_message' => $screen_log_message
2131 );
2132 //PrintHelper::ManageMaintenanceLogs($logs_params_array);
2133 }
2134 }
2135 }
2136 else
2137 {
2138 if( $this->GetDisplayLog() ) {
2139 $log_string = "Success Resetting sf_indexing_flag from 2 to 0 for " . $content_del->data["sf_sf_path"][$s] . $content_del->data["sf_sf_name"][$s];
2140 $this->print_helper_obj->PrintToCMD( $log_string, 2 );
2141
2142 {// Logs
2143 $log_message = $log_string;
2144 $text_log_message = '';
2145 $screen_log_message = "";
2146
2147 $logs_params_array = array(
2148 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
2149 'log_message' => $log_message,
2150 'text_log_message' => $text_log_message,
2151 'screen_log_message' => $screen_log_message
2152 );
2153 PrintHelper::ManageMaintenanceLogs($logs_params_array);
2154 }
2155 }
2156 }
2157 }
2158 }
2159 }
2160
2161 /** Delete all folders */
2162 for ( $s = 0; $s < $content_del->count; $s++ )
2163 {
2164 if( $content_del->data["sf_sf_is_dir"][$s] == 1 )
2165 {
2166 $file_info = array();
2167 $file_info['preview_base_source'] = $content_del->data['sf_sf_preview_base_source'][$s];
2168 $file_info['file_id'] = $content_del->data["sf_sf_id"][$s];
2169 $file_info['file_name'] = $content_del->data["sf_sf_name"][$s];
2170 $file_info['file_name_win1256'] = TextHelper::ConvertFromUTF8ToWIN1256($content_del->data["sf_sf_name"][$s]);
2171 $file_info['file_path'] = $content_del->data["sf_sf_path"][$s];
2172 $file_info['file_path_win1256'] = TextHelper::ConvertFromUTF8ToWIN1256($content_del->data["sf_sf_path"][$s]);
2173 $file_info['file_type'] = $content_del->data["sf_sf_type"][$s];
2174 $file_info['file_parent_id'] = $content_del->data["sf_sf_parent_id"][$s];
2175 $file_info['full_preview_files_paths'] = addslashes( $config['dam_path'] . PREVIEW_FILES_PATHS );
2176 $file_info['sl_path'] = $this->GetStorageLocationPath();
2177 $file_info['sl_id'] = $content_del->data['sf_fk_sl_id'][$s];
2178 $file_info['flg_deleted_on'] = $content_del->data['sf_sf_flagged_as_deleted_date'][$s];
2179
2180 if( ShouldActivateDelete($file_info, true) )
2181 {
2182 $delete_msg = "Deleting Folder " . $content_del->data["sf_sf_name"][$s] . " : "; // Keep folder path
2183
2184 if( DeleteFolderFromDB( $file_info ) )
2185 {
2186 $delete_msg .= "Resources Files of Folder Deleted Successfully";
2187 }
2188 else
2189 {
2190 $this->SetIndexingError( $content_del->data["sf_sf_id"][$s], 6 );
2191 $success = 0;
2192 $delete_msg .= $error_msg;
2193 }
2194
2195 if( $this->GetDisplayLog() ) { PrintHelper::PrintToCMD( $delete_msg, 2 ); }
2196
2197 {// Logs
2198 $log_message = $delete_msg;
2199 $text_log_message = '';
2200 $screen_log_message = "";
2201
2202 $logs_params_array = array(
2203 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
2204 'log_message' => $log_message,
2205 'text_log_message' => $text_log_message,
2206 'screen_log_message' => $screen_log_message
2207 );
2208 PrintHelper::ManageMaintenanceLogs($logs_params_array);
2209 }
2210
2211 unset($file_info);
2212 }
2213 else
2214 {
2215 if(!$this->ResetDeleteFlag( $content_del->data["sf_sf_id"][$s] ) )
2216 {
2217 if( $this->GetDisplayLog() ) {
2218 $log_string = "Error: Resetting sf_indexing_flag from 2 to 0 for " . $content_del->data["sf_sf_path"][$s] . $content_del->data["sf_sf_name"][$s] . " ( DB Content :: QuickLongIndex() )";
2219 $this->print_helper_obj->PrintToCMD( $log_string, 2 );
2220 }
2221 }
2222 else
2223 {
2224 if( $this->GetDisplayLog() ) {
2225 $log_string = "Success Resetting sf_indexing_flag from 2 to 0 for " . $content_del->data["sf_sf_path"][$s] . $content_del->data["sf_sf_name"][$s];
2226 $this->print_helper_obj->PrintToCMD( $log_string, 2 );
2227 }
2228 }
2229
2230 {// Logs
2231 $log_message = $log_string;
2232 $text_log_message = '';
2233 $screen_log_message = "";
2234
2235 $logs_params_array = array(
2236 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
2237 'log_message' => $log_message,
2238 'text_log_message' => $text_log_message,
2239 'screen_log_message' => $screen_log_message
2240 );
2241 //PrintHelper::ManageMaintenanceLogs($logs_params_array);
2242 }
2243 }
2244 }
2245 }
2246 }
2247
2248 unset( $content_del );
2249
2250 if( $success ) { return true; }
2251 else { return false; }
2252 }
2253
2254
2255 /**
2256 * Insert File or folder into DB
2257 *
2258 * @param Array $file :: Holds different file information
2259 * @param INT $dir_id
2260 * @param INT $file_count
2261 * @param INT $file_size
2262 * @param INT $folder_count
2263 * @param INT $indexing_flag
2264 * @param Boolean $prepare_mode
2265 * @return AdvancedConnectSql result array
2266 */
2267 function PrepareFileFolderInsertion ( &$file, $dir_id, &$file_count, &$file_size, &$folder_count, $indexing_flag = 0 )
2268 {
2269 global $dateformat;
2270
2271 $path = DirectoryHelper::ConvertSLPathFromFullToRelative( TextHelper::ConvertFromWIN1256ToUTF8($file['path']), $this->GetStorageLocationPath() );
2272 $file_name = addslashes( TextHelper::ConvertFromWIN1256ToUTF8($file['name']) );
2273 $file_name_info = FileHelper::NormalGetFileNameAndExtension ( $file_name );
2274
2275 if ( $file['dir'] )
2276 {
2277 $folder_count++;
2278 $this->fldrs_files_queries[] = " ('" . addslashes($path) . "','" . ($file_name) . "', '', '" . $this->GetStorageLocationID() . "', '', 1, '', 0, NOW(), " . $indexing_flag . ", NOW(), NOW(), " . $dir_id . ", 1, " . $this->GetQuickOrLongIndex() . ")";
2279 }
2280 else
2281 {
2282 $full_file_path = $file['path'] . "/" . TextHelper::ConvertFromUTF8ToWIN1256( $file_name );
2283 $file_modified_date = date( $dateformat, filemtime( $full_file_path ) );
2284 $file_creation_date = date( $dateformat, filectime( $full_file_path ) );
2285
2286 $file_count++;
2287 $file_size += $file['size'];
2288
2289 $this->fldrs_files_queries[] = " ('" . addslashes($path) . "','" . ($file_name) . "', '" . $file_name_info['file_name'] . "', '" . $this->GetStorageLocationID() . "', '" . strtoupper( addslashes( $file_name_info['extension'] ) ) . "', 0, '" . $this->fldrs_to_index_obj->CreateFilePreviewBaseSrc() . "', '" . $file['size'] . "', NOW(), 0, '" . $file_creation_date . "', '" . $file_modified_date . "', " . $dir_id . ", 1, " . $this->GetQuickOrLongIndex() . ")";
2290 }
2291 }
2292
2293 /**
2294 * Insert prepared data from PrepareFileFolderInsertion() to DB
2295 *
2296 * @return Boolean
2297 */
2298 function InsertFileFolderToDB ()
2299 {
2300 global $tableCollab;
2301
2302 if ( count( $this->fldrs_files_queries ) > 0 )
2303 {
2304 $fldrs_files_queries_chuncked_values = array_chunk( $this->fldrs_files_queries, 1000 );
2305 // Main query
2306
2307 foreach ( $fldrs_files_queries_chuncked_values as $chunk )
2308 {
2309 $insert_query = "INSERT IGNORE INTO " . $tableCollab["system_files"] . "(sf_path, sf_name, sf_title, fk_sl_id, sf_type, sf_is_dir, sf_preview_base_source, sf_size, sf_inserting_date, sf_indexing_flag, sf_creation_date, sf_modification_date, sf_parent_id, sf_is_updated, sf_insert_from ) VALUES";
2310
2311 $insert_query .= implode( ",", $chunk );
2312 $res = AdvancedConnectSql( $insert_query );
2313
2314 if ( $res['query_error'] != 0 )
2315 {
2316 $log_string = $insert_query;
2317 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
2318 return false;
2319 }
2320 }
2321 }
2322
2323 return true;
2324 }
2325
2326 /**
2327 * Flag a folder or file for deletion. If a folder we flag all its children as well.
2328 * Deleted flag is 2
2329 *
2330 * @param INT $file_id :: File/Folder id
2331 * @param String $file_path :: File/Folder path
2332 * @param Boolean (0/1) $is_dir
2333 */
2334 function FlagContentAsDeleted( $file_id, $file_path, $file_name, $is_dir )
2335 {
2336 global $tableCollab;
2337
2338 /** If directory flag it and all its children for deletion */
2339 if ( $is_dir )
2340 {
2341 if( ( $file_path == "./" && strlen( trim( $file_name) ) == 0 ) || !self::CheckIfRootAccessible() )
2342 {
2343 return true;
2344 }
2345
2346 $file_name = ( strlen($file_name) == 0 ? "/" : $file_name . "/" );
2347
2348 //$update_cond = " sf_parent_id=" . $file_id . " OR sf_id=" . $file_id;
2349 $update_cond = " (sf_path LIKE '" . addslashes($file_path) . addslashes($file_name) . "%' OR sf_id=" . $file_id . ') AND fk_sl_id=' . $this->GetStorageLocationID();
2350
2351 $params = array( 'dir_id' => $file_id, 'type' => 'all' );
2352 $sf_ids = DirectoryHelper::RetrieveAllFilesFoldersIdsUnderFolder( $params );
2353 $sf_ids = array_merge( $sf_ids, array( $file_id ) );
2354
2355 $sf_ids_chuncked_values = array_chunk( $sf_ids, 1000 );
2356
2357 foreach ( $sf_ids_chuncked_values as $chunk )
2358 {
2359 $update_query = "UPDATE " . $tableCollab["system_files"] . " SET sf_indexing_flag=2, sf_flagged_as_deleted_date=NOW() WHERE sf_id IN(" . implode( ",", $chunk ) . ") AND sf_indexing_flag!='4'" ;
2360 $res = AdvancedConnectSql( $update_query );
2361 }
2362 }
2363 else
2364 {
2365 $update_cond = " sf_id=" . $file_id;
2366 $update_query = "UPDATE " . $tableCollab["system_files"] . " SET sf_indexing_flag=2, sf_flagged_as_deleted_date=NOW() WHERE" . $update_cond . " AND fk_sl_id = '" . $this->GetStorageLocationID() . "' AND sf_indexing_flag!='4'" ;
2367 $res = AdvancedConnectSql( $update_query );
2368 }
2369
2370 {// Logs
2371 $log_message = 'Quick Index: Flagging as to be deleted; file/folder id -> ' . $file_id . '; path -> ' . addslashes($file_path) . addslashes($file_name);
2372 $text_log_message = '';
2373 $screen_log_message = 'Flagging as to be deleted; file/folder id -> ' . $file_id . '; path -> ' . addslashes($file_path) . addslashes($file_name) . "\n";
2374
2375 $logs_params_array = array(
2376 'm_type' => MaintenanceLogsManager::MM1_QUICK_INDEX,
2377 'log_message' => $log_message,
2378 'text_log_message' => '',
2379 'sf_id' => $file_id,
2380 'sl_id' => $this->GetStorageLocationID(),
2381 'sf_path' => addslashes( $file_path ),
2382 'sf_name' => addslashes( $file_name ),
2383 'screen_log_message' => $screen_log_message
2384 );
2385 PrintHelper::ManageMaintenanceLogs($logs_params_array);
2386 }
2387
2388 if ( $res['query_error'] == 1 ) {
2389 $log_string = $update_query;
2390 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
2391 return false;
2392 }
2393 else { return true; }
2394 }
2395
2396 /**
2397 * Read Folder content and store in an array
2398 * (N.B: The base path doesn't contain an ending slash)
2399 *
2400 * @param String $directory
2401 * @return void
2402 */
2403 function ReadFolderContent( $directory )
2404 {
2405 unset($this->physical_fldr_content);
2406
2407 $print_function = $this->GetOutputPrintFn();
2408
2409 /** If time log is flagged to true */
2410 if ( $this->GetTimeLog() && $this->GetDisplayLog() ) { $start_load = DateHelper::StartLoad(); }
2411
2412 /** If directory couldn't be found */
2413 if ( !$this->IsDirectory( $directory ) ) { return 0; }
2414
2415 if( $config['operating_system'] == 'windows' )
2416 {
2417 /** If directory is not readable */
2418 if ( !$this->IsDirectoryReadable( $directory ) ) { return 0; }
2419 }
2420
2421 $directory_list = opendir( TextHelper::ConvertFromUTF8ToWIN1256($directory ));
2422
2423 while ( FALSE !== ( $file = readdir( $directory_list ) ) )
2424 {
2425 $treat_as_file = false;
2426
2427 if( $file != '.' && $file != '..' )
2428 {
2429 if( strlen( trim( $file ) ) == 0 )
2430 {
2431 break;
2432 }
2433
2434 $file_utf8 = TextHelper::ConvertFromWIN1256ToUTF8( $file );
2435
2436 $base_path = TextHelper::ConvertFromUTF8ToWIN1256( $directory );
2437 $path = $base_path . "/" . $file; // Build path of current fetched file/folder
2438
2439 $file_name_info = FileHelper::NormalGetFileNameAndExtension( TextHelper::ConvertFromWIN1256ToUTF8($file) );
2440
2441 /** check if we want to treat a folder as a file */
2442 if ( DirectoryHelper::TreatFolderAsFile( $file_name_info ) ) { $is_dir = false; $treat_as_file = true; }
2443 else if( is_dir( $path ) ) { $is_dir = true;}
2444 else { $is_dir = false; }
2445
2446 if ( $treat_as_file ) {
2447 $fldr_info = DirectoryHelper::GetDirectorySize( $path );
2448 $current_file_size = $fldr_info['size'];
2449 //$current_file_size = 0;
2450 }
2451 else
2452 {
2453 if ( !$is_dir ) { $current_file_size = filesize( $path ); }
2454 }
2455
2456 if ( $current_file_size == "" && !$is_dir )
2457 {
2458 $current_file_size = 0;
2459 $log_string = "ERROR: File came with size empty in ReadFolderContent(): " . $path;
2460 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
2461 }
2462
2463 $this->physical_fldr_content[$file_utf8]['name'] = $file; // WINDOWS-1256
2464 $this->physical_fldr_content[$file_utf8]['dir'] = $is_dir;
2465 $this->physical_fldr_content[$file_utf8]['size'] = $current_file_size;
2466 $this->physical_fldr_content[$file_utf8]['path'] = $base_path ; // WINDOWS-1256
2467 $this->physical_fldr_content[$file_utf8]['treat_as_file'] = $treat_as_file;
2468 }
2469 }
2470
2471 if ( $this->GetTimeLog() && $this->GetDisplayLog() ) {
2472 $total_time = round( ( DateHelper::FinishLoad() - $start_load), 6 );
2473 $log_string = "<span class='error errorBorder'>Reading Folder Content Finished in " . $total_time . " Seconds </span>";
2474 $this->print_helper_obj->$print_function( $log_string, 2 );
2475 }
2476
2477 return 1;
2478 }
2479
2480 /**
2481 * Retrieve Folders flagged for indexing (i.e: sf_indexing_flag = 1)
2482 *
2483 * @return void
2484 */
2485 function RetrieveFoldersFlaggedForIndexing ()
2486 {
2487 global $tableCollab, $config;
2488
2489 $this->fldrs_to_index_obj = new FileManager();
2490 $this->fldrs_to_index_obj->members_array = array( "sf.sf_id", "sf.sf_path", "sf.sf_name", "sf.sf_size", "sf.sf_parent_id", "sf.sf_is_dir", "sf.fk_sl_id", "sf.sf_is_indexing_error", "sf.sf_indexing_flag" );
2491
2492 if( $this->maintenance_type != "index_location" )
2493 {
2494 $query_cond = " WHERE sl_id = '" . $this->GetStorageLocationID() . "'";
2495
2496 $maintenance_run_obj = new MaintenanceRun();
2497 $maintenance_run_obj->start = 0;
2498 $maintenance_run_obj->display = $config['indexing_limit'];
2499 $maintenance_run_obj->members_array = array( "mir.sf_id" );
2500 $maintenance_run_obj->GetIndexRun( $query_cond );
2501
2502 if( $maintenance_run_obj->count > 0 )
2503 {
2504 $order_by_fields['remove_order_by'] = 1;
2505 $extra_params['indexing_flag'] = 1;
2506 $query_cond = " WHERE sf_id IN(" . implode( ",", $maintenance_run_obj->data["mir_sf_id"] ) . ")";
2507 $this->fldrs_to_index_obj->GetFiles( $query_cond, $order_by_fields, $extra_params );
2508 }
2509 }
2510 else
2511 {
2512 $query_cond = " WHERE fk_sl_id = '" . $this->GetStorageLocationID() . "'";
2513 $this->fldrs_to_index_obj->GetFiles( $query_cond );
2514 }
2515 }
2516
2517 /**
2518 * Retrieve contents of folders from DB
2519 *
2520 * @param String $query_cond
2521 * @param INT $fetch_by :: Defines if we wish to fetch by path 0 or parent id 1
2522 */
2523 function RetrieveFolderContents ( $query_cond, $fetch_by )
2524 {
2525 $print_function = $this->GetOutputPrintFn();
2526
2527 /** If time log is flagged to true */
2528 if ( $this->GetTimeLog() && $this->GetDisplayLog() ) { $start_load = DateHelper::StartLoad(); }
2529
2530 $this->fldrs_content_obj = new FileManager();
2531 $this->fldrs_content_obj->members_array = array( "sf.sf_id", "sf.sf_name", "sf.sf_size", "sf.sf_path", "sf.sf_is_dir", "sf.sf_indexing_flag", "sf.sf_parent_id", "sf.fk_sl_id", "sf.sf_preview_base_source" );
2532
2533 if ( $fetch_by == 0 )
2534 {
2535 //$query_cond = " WHERE sf.sf_path IN(" . $query_cond . ") AND sf.fk_sl_id = " . $this->GetStorageLocationID() . " AND sf_indexing_flag != 2";
2536 $query_cond = " WHERE sf.sf_path IN(" . $query_cond . ") AND sf.fk_sl_id = '" . $this->GetStorageLocationID() . "'";
2537 }
2538 else if ( $fetch_by == 1 )
2539 {
2540 //$query_cond = " WHERE sf.sf_parent_id=" . $query_cond . " AND sf.fk_sl_id = " . $this->GetStorageLocationID() . " AND sf_indexing_flag != 2";
2541 $query_cond = " WHERE sf.sf_parent_id='" . $query_cond . "' AND sf.fk_sl_id = '" . $this->GetStorageLocationID() . "'";
2542 }
2543
2544 $extra_params['indexing_flag'] =1;
2545 $this->fldrs_content_obj->GetFiles( $query_cond, null, $extra_params );
2546 //$this->folder_contents = $this->fldrs_content_obj->data["sf_sf_name"];
2547
2548 /** Fill data into a special array so it can be easily referenced */
2549 $this->FillDBFolderContent ();
2550
2551 if ( $this->GetTimeLog() && $this->GetDisplayLog() ) {
2552 $total_time = round( ( DateHelper::FinishLoad() - $start_load), 6 );
2553
2554 $log_string = "<span class='error errorBorder'>Retrieving Folder Content Finished in " . $total_time . " Seconds </span>";
2555 $this->print_helper_obj->$print_function( $log_string, 2 );
2556 }
2557 }
2558
2559 /**
2560 * Fill folder content retrieved from DB into array
2561 * $this->folder_contents[path][name]
2562 *
2563 * @return void
2564 */
2565 function FillDBFolderContent ()
2566 {
2567 for ( $n = 0; $n < $this->fldrs_content_obj->count; $n++ )
2568 {
2569 $sf_path = $this->fldrs_content_obj->data['sf_sf_path'][$n];
2570 $sf_name = $this->fldrs_content_obj->data['sf_sf_name'][$n];
2571 $sf_flag = $this->fldrs_content_obj->data['sf_indexing_flag'][$n];
2572
2573 $this->folder_contents[$sf_path][$sf_name] = 1;
2574 }
2575 }
2576
2577 /**
2578 * Retrieve contents flagged as deleted
2579 *
2580 * @return FileManager Object
2581 */
2582 function RetrieveContentFlaggedAsDeleted ( $indexing_flag = 2 )
2583 {
2584 global $config;
2585
2586 $date = date("Y-m-d H:i:s", strtotime( date("Y-m-d H:i:s" ) . "-" . $config['indexer_delete_interval'] . " minute" . " +" . $config['timezone'] . " Hour") );
2587
2588 $del_content_obj = new FileManager();
2589 $del_content_obj->members_array = array( "sf.sf_id", "sf.fk_sl_id" , "sf.sf_name", "sf.sf_path", "sf.sf_is_dir", "sf.sf_preview_base_source", "sf.sf_type", "sf.sf_parent_id", "sf.sf_flagged_as_deleted_date" );
2590
2591 $query_cond = " WHERE sf.fk_sl_id = '" . $this->GetStorageLocationID() . "' AND sf.sf_indexing_flag='" . $indexing_flag . "' AND sf.sf_flagged_as_deleted_date < '" . $date . "'";
2592
2593 $extra_params = array();
2594 $extra_params['indexing_flag'] = 1;
2595 $del_content_obj->start = 0;
2596 $del_content_obj->display = $config['indexing_limit'];
2597 $del_content_obj->GetFiles( $query_cond, array("sf.sf_id DESC"), $extra_params );
2598
2599 return $del_content_obj;
2600 }
2601
2602 /**
2603 * Build Query condition based on the specified case
2604 *
2605 * @param String $case
2606 */
2607 function BuildGeneralQueryConditions ( $case = null )
2608 {
2609 $query_cond = "";
2610
2611 switch ( $case ) {
2612
2613 /** Used in case of initial indexing where i want to retrieve data in all folders flagged for indexing */
2614 case "fldrs_to_index_content":
2615 {
2616 /** Build the IN(---) condition */
2617 for( $i = 0 ; $i < $this->fldrs_to_index_obj->count ; $i++ )
2618 {
2619 $dir_full_path = $this->fldrs_to_index_obj->data["sf_sf_path"][$i] . $this->fldrs_to_index_obj->data["sf_sf_name"][$i];
2620
2621 $query_cond .= "'" . ( $dir_full_path == "./" ? addslashes( $dir_full_path ) : addslashes( $dir_full_path ) . "/" ) . "',";
2622 }
2623
2624 $query_cond = substr( $query_cond , 0, strlen( $query_cond ) - 1 );
2625 }
2626 break;
2627 }
2628
2629 return $query_cond;
2630 }
2631
2632 /**
2633 * Set an indexing error flag based on the error type that happened during indexing
2634 *
2635 * @param String $directory
2636 * @param INT $indexing_error :: Indexing error type
2637 * @param String $reset_dir_path :: if this variable not null also flag all sub folders of this path
2638 */
2639 function SetIndexingError ( $dir_id, $indexing_error = 1, $reset_dir_path = null )
2640 {
2641 global $tableCollab;
2642
2643 $maintenance_run_obj = new MaintenanceRun();
2644
2645 $indexing_error_query = "UPDATE " . $tableCollab["system_files"] . " SET sf_is_indexing_error=" . $indexing_error . ", sf_indexing_flag=0 WHERE sf_id='" . $dir_id . "' AND fk_sl_id = '" . $this->GetStorageLocationID() . "'" ;
2646 $res = AdvancedConnectSql( $indexing_error_query );
2647
2648 if( $reset_dir_path != null )
2649 {
2650 $indexing_error_query = "UPDATE " . $tableCollab["system_files"] . " SET sf_is_indexing_error=" . $indexing_error . ", sf_indexing_flag=0 WHERE sf_path LIKE '" . $reset_dir_path . "% AND fk_sl_id = '" . $this->GetStorageLocationID() . "'" ;
2651 $res = AdvancedConnectSql( $indexing_error_query );
2652 }
2653 }
2654
2655 /**
2656 * Update file count, file size, folder count
2657 *
2658 * @param Array $params_array
2659 */
2660 function SetFolderParams ( $dir_id, $params_array = array() )
2661 {
2662 global $tableCollab;
2663
2664 $maintenance_run_obj = new MaintenanceRun();
2665
2666 if( !is_numeric( $params_array['file_size'] ) )
2667 {
2668 return false;
2669 }
2670
2671 $update_query = "UPDATE " . $tableCollab["system_files"] . " SET sf_size = " . $params_array['file_size'] . ", sf_indexing_flag=0 WHERE sf_id='" . $dir_id . "'";
2672 $res = AdvancedConnectSql( $update_query );
2673
2674 if ( $res['query_error'] == 1 )
2675 {
2676 $log_string = $update_query;
2677 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
2678
2679 return false;
2680 }
2681 else
2682 {
2683 return true;
2684 }
2685 }
2686
2687 /**
2688 * Flag all folders or specific folders indexing i.e indexing flag = 1 but for folders that are not flagged for deletion
2689 *
2690 * @param String $folder
2691 * @return Boolean
2692 */
2693 function FlagFoldersForIndexing ()
2694 {
2695 global $tableCollab, $config;
2696
2697 $update_query = "UPDATE " . $tableCollab["system_files"] . " SET sf_indexing_flag=1 WHERE sf_is_dir=1 AND sf_indexing_flag != '2'" . ( $config['delete_folders'] == 1 ? " AND sf_indexing_flag != '5'" : "" ) . ( strlen( trim( $this->GetDirPath() ) ) > 0 ? " AND sf_path LIKE '" . $this->GetDirPath() . "%'" : "" ) . " AND fk_sl_id=" . $this->GetStorageLocationID();
2698 $res = AdvancedConnectSql( $update_query );
2699
2700 if ( $res['query_error'] == 1 ) {
2701 $log_string = $update_query;
2702 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
2703 return false;
2704 }
2705 else { return true; }
2706
2707 }
2708
2709 /**
2710 * Regenerate file data
2711 *
2712 * @param INT $file_id
2713 * @return Boolean
2714 */
2715 function RegenerateFileData ( $file_id, $current_file_size )
2716 {
2717 global $tableCollab;
2718
2719 $current_file_size = ( strlen( trim( $current_file_size ) ) > 0 ? $current_file_size : 0 );
2720
2721 $update_query = "UPDATE " . $tableCollab["system_files"] . " SET sf_size=" . $current_file_size . ", sf_is_text_extracted=0, sf_is_exif_extracted=0, sf_preview_page=0, sf_is_preview=0, sf_preview_retries=0 WHERE sf_id='" . $file_id . "'";
2722 $res = AdvancedConnectSql( $update_query );
2723
2724 if ( $res['query_error'] == 1 ) {
2725 $log_string = $update_query;
2726 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
2727
2728 return false;
2729 }
2730 else
2731 {
2732 return true;
2733 }
2734 }
2735
2736 /**
2737 * Build Unique XML file
2738 * (N.B: $params_array['directory'] doesn't contain an ending slash )
2739 *
2740 * @param Array $params_array
2741 */
2742 function BuildUniqueFile ( $params_array )
2743 {
2744 global $basdir;
2745
2746 $generate_file = 1;
2747
2748 $unique_file = $params_array['directory'] . "/" . $this->GetUniqueFileName();
2749 $unique_file_result = self::RetrieveLastUniqueFileGenerated( $unique_file );
2750
2751 $unique_file = $unique_file_result['current_file'];
2752
2753 if( is_file( $unique_file ) )
2754 {
2755 $unique_file_data = $this->ParseUniqueFile( $unique_file );
2756
2757 if( $params_array['parent_id'] == $unique_file_data['parent_id'] )
2758 {
2759 $generate_file = 0;
2760 }
2761 }
2762
2763 if( $generate_file )
2764 {
2765 $file_data = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
2766 $file_data .= "<folder>" . "\n";
2767 $file_data .= " <dir_path><![CDATA[" . TextHelper::ConvertFromWIN1256ToUTF8($params_array['directory']) . "/" . "]]></dir_path>" . "\n";
2768 $file_data .= " <dir_base><![CDATA[" . TextHelper::ConvertFromWIN1256ToUTF8($params_array['directory_base']) . "/" . "]]></dir_base>" . "\n";
2769 $file_data .= " <directory_name><![CDATA[" . TextHelper::ConvertFromWIN1256ToUTF8($params_array['directory_name']) . "]]></directory_name>" . "\n";
2770
2771 $file_data .= " <old_dir_path><![CDATA[" . TextHelper::ConvertFromWIN1256ToUTF8($params_array['old_directory']) . "]]></old_dir_path>" . "\n";
2772 $file_data .= " <old_directory_base_path><![CDATA[" . TextHelper::ConvertFromWIN1256ToUTF8($params_array['old_directory_base_path']) . "]]></old_directory_base_path>" . "\n";
2773 $file_data .= " <old_directory_name><![CDATA[" . TextHelper::ConvertFromWIN1256ToUTF8($params_array['old_directory_name']) . "]]></old_directory_name>" . "\n";
2774
2775 $file_data .= " <dir_id>" . $params_array['directory_id'] . "</dir_id>" . "\n";
2776 $file_data .= " <parent_id>" . $params_array['parent_id'] . "</parent_id>" . "\n";
2777 $file_data .= " <date>" . DateHelper::RetrieveDateTimeZone() . "</date>" . "\n";
2778 $file_data .= "</folder>";
2779
2780 //copy( DA_BASE_SRC . "app/docs/.a7pro.xml", $params_array['directory'] . "/" . $this->GetUniqueFileName() );
2781
2782 $unique_file_result = self::RetrieveLastUniqueFileGenerated( $params_array['directory'] . "/" . $this->GetUniqueFileName() );
2783
2784 $fp = fopen( $unique_file_result['current_file'], 'w' );
2785 $write_res = fwrite( $fp, $file_data );
2786 fclose( $fp );
2787
2788 if( $write_res === FALSE ) { return false; }
2789 else { return true; }
2790 }
2791 else
2792 {
2793 return TRUE;
2794 }
2795 }
2796
2797 /**
2798 * Check if the folder is in the rejected
2799 *
2800 * @param String $dir_name
2801 * @return Boolean
2802 */
2803 function IsDirectoryRejected( $dir_name )
2804 {
2805 if( $dir_name[0] == "." || $dir_name == "network trash folder" || $dir_name == "__MACOSX" || $dir_name == "System Volume Information" || $dir_name == '$RECYCLE.BIN' ) { return true; }
2806 else { return false; }
2807 }
2808
2809 /**
2810 * Check if the folder is in the rejected
2811 *
2812 * @param String $file_name
2813 * @return Boolean
2814 */
2815 function IsFileRejected( $file_name )
2816 {
2817 if( $file_name[0] == "." || $file_name == "autorun.inf" || substr_count( $file_name, "exiftool_tmp" ) > 0 )
2818 {
2819 return true;
2820
2821 }
2822 else
2823 {
2824 return false;
2825 }
2826 }
2827
2828 /**
2829 * Check if the file belongs to the rejected file extension
2830 *
2831 * @param String $extension
2832 * @return Boolean
2833 */
2834 function IsFileInRejectedList( $extension )
2835 {
2836 global $rejected_files;
2837 return in_array( strtoupper( $extension ), $rejected_files );
2838 }
2839
2840 /**
2841 * Checks whether the file/folder already exists in DB
2842 *
2843 * @param Strinhg $file
2844 * @return Boolean
2845 */
2846 function IsFileInDB ( $directory, $file )
2847 {
2848 $directory = DirectoryHelper::ConvertSLPathFromFullToRelative( $directory, $this->GetStorageLocationPath() );
2849 $file = TextHelper::ConvertFromWIN1256ToUTF8( $file );
2850
2851 return isset( $this->folder_contents[$directory][$file] );
2852 }
2853
2854 /**
2855 * Performs is_dir() check and logs required errors
2856 *
2857 * @param String $directory
2858 * @return Boolean
2859 */
2860 function IsDirectory ( $directory )
2861 {
2862 /** If directory couldn't be found */
2863 if ( !is_dir( TextHelper::ConvertFromUTF8ToWIN1256( $directory ) ) )
2864 {
2865 if( $this->GetDisplayLog() ) {
2866 $log_string = "ERROR: Folder did not behave directory: " . $directory;
2867 PrintHelper::PrintToCMD( $log_string, 2 );
2868 }
2869
2870 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
2871
2872 return false;
2873 }
2874 return true;
2875 }
2876
2877 /**
2878 * Performs is_readable() check and logs required errors
2879 *
2880 * @param String $directory
2881 * @return Boolean
2882 */
2883 function IsDirectoryReadable ( $directory )
2884 {
2885 if ( !is_readable( TextHelper::ConvertFromUTF8ToWIN1256( $directory ) ) )
2886 {
2887 if( $this->GetDisplayLog() ) {
2888 $log_string = "ERROR: Folder is not readable: " . $directory;
2889 PrintHelper::PrintToCMD( $log_string, 2 );
2890 }
2891
2892 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), $log_string, "ab+", 2 );
2893
2894 return false;
2895 }
2896 return true;
2897 }
2898
2899 /**
2900 * Checks if we are running the class from the maintenance
2901 *
2902 * @return Boolean
2903 */
2904 function IsMaintenance ()
2905 {
2906 if ( $this->GetUsageType() == 'maintenance' ) { return true; }
2907 else { return false; }
2908 }
2909
2910 /**
2911 * Checks if we are running the class from the autoindex
2912 *
2913 * @return Boolean
2914 */
2915 function IsAutoIndex ()
2916 {
2917 if ( $this->GetUsageType() == 'autoindex' ) { return true; }
2918 else { return false; }
2919 }
2920
2921 /**
2922 * Checks if we are running the class from the reindex page
2923 *
2924 * @return Boolean
2925 */
2926 function IsReIndex ()
2927 {
2928 if ( $this->GetUsageType() == 'reindex' ) { return true; }
2929 else { return false; }
2930 }
2931
2932 /**
2933 * Checks if we are running the class from the reindex curl page
2934 *
2935 * @return Boolean
2936 */
2937 function IsReIndexCurl ()
2938 {
2939 if ( $this->GetUsageType() == 'reindex_curl' ) { return true; }
2940 else { return false; }
2941 }
2942
2943 /**
2944 * Set new folder flag based from where we are launching the indexing
2945 *
2946 * @return INT
2947 */
2948 function GetNewFolderFlag ()
2949 {
2950 if ( $this->IsMaintenance() ) { return 1; }
2951 else if ( $this->IsAutoIndex() ) { return 3; }
2952 else if ( $this->IsReIndex() ) { return 1; }
2953 else if ( $this->IsReIndexCurl() ) { return 1; }
2954 }
2955
2956 /**
2957 * Define what is the print function that will output the text
2958 * Either to browser or to CMD
2959 *
2960 * @return String :: Print function name
2961 */
2962 function GetOutputPrintFn ()
2963 {
2964 if ( $this->IsReIndex() || $this->IsAutoIndex() ) { return "PrintToBrowser"; }
2965 else { return "PrintToCMD"; }
2966 }
2967
2968 /**
2969 * Delete flagged content data and DB records
2970 *
2971 * @return boolean
2972 */
2973 function DeleteFlaggedFiles ( $extra_params = array() )
2974 {
2975 global $tableCollab, $config , $def_triggers;
2976 $success = 1;
2977 $copy_error = array();
2978
2979 $content_del = new FileManager();
2980 $content_del->members_array = array( "sf.sf_id", "sf.fk_sl_id" , "sf.sf_name", "sf.sf_path", "sf.sf_is_dir", "sf.sf_preview_base_source", "sf.sf_type", "sf.sf_parent_id", "sf.sf_flagged_as_deleted_date" );
2981
2982 if( $extra_params['is_dir'] == 0 )
2983 {
2984 $query_cond = " WHERE sf.fk_sl_id = '" . $extra_params['sl_id'] . "' AND sf.sf_id='" . $extra_params['sf_id'] . "'";
2985 }
2986 else
2987 {
2988 $query_cond = " WHERE sf.fk_sl_id = '" . $extra_params['sl_id'] . "' AND ( sf.sf_path LIKE '" . addslashes( $extra_params['sf_path'] . $extra_params['sf_name'] ) . "%' OR sf.sf_id='" . $extra_params['sf_id'] . "' )";
2989 }
2990
2991 $query_cond .= " AND sf_indexing_flag IN(2,5)";
2992
2993 $order_by_fields = array();
2994 $order_by_fields[] = "sf.sf_path DESC";
2995 $order_by_fields[] = "sf.sf_is_dir ASC";
2996
2997 $extra_params['indexing_flag'] = 1;
2998
2999 $content_del->GetFiles( $query_cond, $order_by_fields, $extra_params );
3000
3001 /** If there is data to be deleted */
3002 if ( $content_del->count > 0 )
3003 {
3004 $db_begin_res = AdvancedConnectSql( "BEGIN;" );
3005
3006 /** Delete all folders */
3007 for ( $s = 0; $s < $content_del->count; $s++ )
3008 {
3009 $file_info = array();
3010 $file_info['preview_base_source'] = $content_del->data['sf_sf_preview_base_source'][$s];
3011 $file_info['file_id'] = $content_del->data["sf_sf_id"][$s];
3012 $file_info['file_name'] = $content_del->data["sf_sf_name"][$s];
3013 $file_info['file_name_win1256'] = TextHelper::ConvertFromUTF8ToWIN1256($content_del->data["sf_sf_name"][$s]);
3014 $file_info['file_path'] = $content_del->data["sf_sf_path"][$s];
3015 $file_info['file_path_win1256'] = TextHelper::ConvertFromUTF8ToWIN1256($content_del->data["sf_sf_path"][$s]);
3016 $file_info['file_type'] = $content_del->data["sf_sf_type"][$s];
3017 $file_info['file_parent_id'] = $content_del->data["sf_sf_parent_id"][$s];
3018 $file_info['full_preview_files_paths'] = addslashes( $config['dam_path'] . PREVIEW_FILES_PATHS );
3019 $file_info['sl_id'] = $content_del->data['sf_fk_sl_id'][$s];
3020 $file_info['sl_path'] = $this->GetStorageLocationPath();
3021 $file_info['flg_deleted_on'] = $content_del->data['sf_sf_flagged_as_deleted_date'][$s];
3022
3023 if( $content_del->data["sf_sf_is_dir"][$s] == 1 )
3024 {
3025 if( DeleteFolderFromDB( $file_info ) )
3026 {
3027 //DirectoryHelper::UpdateFolderCount( $content_del->data["sf_sf_parent_id"][$s] );
3028 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), "Deleting Folder " . $content_del->data["sf_sf_name"][$s] . " Successfully from db", "ab+", 2 );
3029 }
3030 else
3031 {
3032 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), " error Deleting Folder " . $content_del->data["sf_sf_name"][$s] . " from db", "ab+", 2 );
3033 $success = 0;
3034 $this->SetIndexingError( $content_del->data["sf_sf_id"][$s], 6 );
3035 }
3036
3037 unset($file_info);
3038 }
3039 else
3040 {
3041 $error_msg = DeleteFileFromDB( $file_info );
3042
3043 if( strlen( trim( $error_msg ) ) == 0 )
3044 {
3045 //DirectoryHelper::UpdateFolderCount( $content_del->data["sf_sf_parent_id"][$s] );
3046 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), "Deleting File " . $content_del->data["sf_sf_name"][$s] . " Successfully from db", "ab+", 2 );
3047
3048// $triggers_obj = new Triggers();
3049// $triggers_obj->data_array['get_data'] = 1;
3050// $triggers_obj->data_array['sf_id'] = $content_del->data["sf_sf_id"][$s];
3051// $triggers_obj->data_array['sl_id'] = $this->GetStorageLocationID();
3052//
3053// $triggers_obj->ManageTriggers( $def_triggers['delete'] );
3054 }
3055 else
3056 {
3057 $this->SetIndexingError( $content_del->data["sf_sf_id"][$s], 6 );
3058 $success = 0;
3059 PrintHelper::PrintToFile( $this->GetLogFolderPath(), $this->GetLogFileName(), " error Deleting File " . $content_del->data["sf_sf_name"][$s] . " from db", "ab+", 2 );
3060 }
3061
3062 unset($file_info);
3063 }
3064 }
3065
3066 if( $success == 0 )
3067 {
3068 $db_rollback_res = AdvancedConnectSql( "ROLLBACK;" );
3069 }
3070 else
3071 {
3072 $db_begin_res = AdvancedConnectSql( "COMMIT;" );
3073 }
3074 }
3075 else
3076 {
3077 $success = 1;
3078 }
3079
3080 if( $success ) { return true; }
3081 else { return false; }
3082 }
3083
3084 public function CheckIfInExcludedList( $directory )
3085 {
3086 foreach ( $this->GetStorageExcludedFolders() as $key => $value )
3087 {
3088 if( strpos( $value, $directory ) !== false )
3089 {
3090 return true;
3091 }
3092 }
3093
3094 return false;
3095 }
3096
3097 /**
3098 * Check if the root of the storage location is accessible
3099 *
3100 * @author Kamil Baderddine
3101 * @access public
3102 *
3103 * @return Boolean
3104 */
3105 public function CheckIfRootAccessible()
3106 {
3107 return DirectoryHelper::IsDirAccessible( $this->GetStorageLocationPath() );
3108 }
3109
3110 function RetrieveDirPathFromID( $dir_id, $dir_name )
3111 {
3112 $file_manager_obj = new FileManager();
3113
3114 $dir_name = stripslashes( $dir_name );
3115 $dir_name = addslashes( $dir_name );
3116
3117 $extra_params = array();
3118 $extra_params['indexing_flag'] = 1;
3119 $order_by_fields = array();
3120 $order_by_fields['remove_order_by'] = 1;
3121
3122 $file_manager_obj->members_array = array( "sf.sf_path", "sf.sf_name", "sf.sf_is_dir" );
3123 $query_more = " WHERE sf_parent_id ='" . $dir_id . "' AND sf_name='" . $dir_name . "'";
3124 $file_manager_obj->GetFiles( $query_more, $order_by_fields, $extra_params );
3125
3126 $unique_file_data['original_path'] = DirectoryHelper::ConvertSLPathFromRelativeToFull( $file_manager_obj->data["sf_sf_path"][0], $this->GetStorageLocationPath() ) . $file_manager_obj->data["sf_sf_name"][0] . "/";
3127 $unique_file_data['dir_base'] = DirectoryHelper::ConvertSLPathFromRelativeToFull( $file_manager_obj->data["sf_sf_path"][0], $this->GetStorageLocationPath() );
3128 $unique_file_data['directory_name'] = $file_manager_obj->data["sf_sf_name"][0];
3129
3130 return $unique_file_data;
3131 }
3132}
3133
3134?>