1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace eoxia; |
4
|
|
|
|
5
|
|
|
if ( !defined( 'ABSPATH' ) ) exit; |
6
|
|
|
|
7
|
|
|
if ( ! class_exists( '\eoxia\log_archive_class' ) ) { |
8
|
|
|
class log_archive_class extends \eoxia\Singleton_Util { |
9
|
|
|
protected function construct() {} |
10
|
|
|
|
11
|
|
|
public function get_archive_file( $name ) { |
12
|
|
|
// Get archive |
13
|
|
|
$upload_dir = wp_upload_dir(); |
14
|
|
|
$dir_file = $upload_dir['basedir'] . '/wpeolog/'; |
15
|
|
|
$array_glob_file = glob( $dir_file . $name . '*.csv' ); |
16
|
|
|
|
17
|
|
|
foreach( $array_glob_file as &$glob_file ) { |
18
|
|
|
$glob_file = explode('/', $glob_file); |
19
|
|
|
$glob_file = $glob_file[count($glob_file) - 1]; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
return $array_glob_file; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* check_need_rotate Checks if the file exceeds the maximum size |
27
|
|
|
* |
28
|
|
|
* @param string $file_link The file path to write |
|
|
|
|
29
|
|
|
*/ |
30
|
|
|
public function check_need_rotate( $service, $name, $message ) { |
31
|
|
|
$upload_dir = wp_upload_dir(); |
32
|
|
|
$max_size = $service['size']; |
33
|
|
|
$file_link = $upload_dir[ 'basedir' ] . '/wpeolog/' . $name . '.csv'; |
34
|
|
|
if( file_exists( $file_link ) ) { |
35
|
|
|
// Get full message |
36
|
|
|
$message = file_get_contents( $file_link ) . $message; |
37
|
|
|
$file_size = filesize( $file_link ); |
38
|
|
|
if($file_size >= $max_size) |
39
|
|
|
self::rename_current_file( $service, $name, $file_link ); |
40
|
|
|
else if(strlen($message) >= $max_size) |
41
|
|
|
self::rename_current_file( $service, $name, $file_link ); |
42
|
|
|
return $file_link; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
/** |
46
|
|
|
* rename_current_file - Rename the current file |
47
|
|
|
* |
48
|
|
|
* @param string $service |
49
|
|
|
* @param string $file_link |
50
|
|
|
*/ |
51
|
|
|
public function rename_current_file( $service, $name, $file_link ) { |
|
|
|
|
52
|
|
|
$upload_dir = wp_upload_dir(); |
53
|
|
|
$number_archive = $service['number']; |
54
|
|
|
if( file_exists ( $file_link ) ) { |
55
|
|
|
$file_explode = explode('.csv', $file_link); |
56
|
|
|
$get_all_file = glob($file_explode[0] . '*.csv'); |
57
|
|
|
array_shift($get_all_file); |
58
|
|
|
arsort($get_all_file); |
59
|
|
|
foreach($get_all_file as $full_file) { |
60
|
|
|
$file = explode('/', $full_file); |
61
|
|
|
$file_name = $file[count($file) - 1]; |
62
|
|
|
$file_name = explode('.', $file_name); |
63
|
|
|
$file_name[0]++; |
64
|
|
|
rename($full_file, $upload_dir[ 'basedir' ] . '/wpeolog/' . $file_name[0] . '.csv'); |
65
|
|
|
// Check if not execeed the number archive |
66
|
|
|
$count = explode('_', $file_name[0]); |
67
|
|
|
if($count[1] > $number_archive && file_exists($upload_dir[ 'basedir' ] . '/wpeolog/' . $file_name[0] . '.csv')) { |
68
|
|
|
unlink($upload_dir[ 'basedir' ] . '/wpeolog/' . $file_name[0] . '.csv'); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
rename( $file_link, $file_explode[0] . '_1.csv' ); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
?> |
|
|
|
|
78
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.