PluginProbe
Tiered Pricing Table for WooCommerce / 2.1.2
Tiered Pricing Table for WooCommerce v2.1.2
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
← All changes | freemius/includes/class-fs-logger.php +20 -57 8.0.2 → 2.1.2 View file →
@@ -31,11 +31,8 @@
31 31 * @var int ABSPATH length.
32 32 */
33 33 private static $_abspathLength;
34 34
35 - /**
36 - * @var FS_Logger[] $LOGGERS
37 - */
38 35 private static $LOGGERS = array();
39 36 private static $LOG = array();
40 37 private static $CNT = 0;
41 38 private static $_HOOKED_FOOTER = false;
@@ -40,12 +37,11 @@
40 37 private static $CNT = 0;
41 38 private static $_HOOKED_FOOTER = false;
42 39
43 40 private function __construct( $id, $on = false, $echo = false ) {
44 - $bt = debug_backtrace();
45 -
46 41 $this->_id = $id;
47 42
43 + $bt = debug_backtrace();
48 44 $caller = $bt[2];
49 45
50 46 if ( false !== strpos( $caller['file'], 'plugins' ) ) {
51 47 $this->_file_start = strpos( $caller['file'], 'plugins' ) + strlen( 'plugins/' );
@@ -126,8 +122,9 @@
126 122 }
127 123
128 124 self::hook_footer();
129 125 }
126 +
130 127 function echo_on() {
131 128 $this->on();
132 129
133 130 $this->_echo = true;
@@ -144,9 +141,9 @@
144 141 function get_file() {
145 142 return $this->_file_start;
146 143 }
147 144
148 - private function _log( &$message, $type, $wrapper = false ) {
145 + private function _log( &$message, $type = 'log', $wrapper ) {
149 146 if ( ! $this->is_on() ) {
150 147 return;
151 148 }
152 149
@@ -321,13 +318,8 @@
321 318 global $wpdb;
322 319
323 320 $table = "{$wpdb->prefix}fs_logger";
324 321
325 - /**
326 - * Drop logging table in any case.
327 - */
328 - $result = $wpdb->query( "DROP TABLE IF EXISTS $table;" );
329 -
330 322 if ( $is_on ) {
331 323 /**
332 324 * Create logging table.
333 325 *
@@ -335,9 +327,9 @@
335 327 * dbDelta must use KEY and not INDEX for indexes.
336 328 *
337 329 * @link https://core.trac.wordpress.org/ticket/2695
338 330 */
339 - $result = $wpdb->query( "CREATE TABLE IF NOT EXISTS {$table} (
331 + $result = $wpdb->query( "CREATE TABLE {$table} (
340 332 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
341 333 `process_id` INT UNSIGNED NOT NULL,
342 334 `user_name` VARCHAR(64) NOT NULL,
343 335 `logger` VARCHAR(128) NOT NULL,
@@ -354,13 +346,17 @@
354 346 KEY `process_id` (`process_id` ASC),
355 347 KEY `process_logger` (`process_id` ASC, `logger` ASC),
356 348 KEY `function` (`function` ASC),
357 349 KEY `type` (`type` ASC))" );
350 + } else {
351 + /**
352 + * Drop logging table.
353 + */
354 + $result = $wpdb->query( "DROP TABLE IF EXISTS $table;" );
358 355 }
359 356
360 357 if ( false !== $result ) {
361 358 update_option( 'fs_storage_logger', ( $is_on ? 1 : 0 ) );
362 - self::$_isStorageLoggingOn = $is_on;
363 359 }
364 360
365 361 return ( false !== $result );
366 362 }
@@ -635,20 +631,10 @@
635 631 $limit = 10000,
636 632 $offset = 0,
637 633 $order = false
638 634 ) {
639 - if ( empty( $filename ) ) {
640 - $filename = 'fs-logs-' . date( 'Y-m-d_H-i-s', WP_FS__SCRIPT_START_TIME ) . '.csv';
641 - }
635 + global $wpdb;
642 636
643 - $upload_dir = wp_upload_dir();
644 - $filepath = rtrim( $upload_dir['path'], '/' ) . "/{$filename}";
645 -
646 - WP_Filesystem();
647 - if ( ! $GLOBALS['wp_filesystem']->is_writable( dirname( $filepath ) ) ) {
648 - return false;
649 - }
650 -
651 637 $query = self::build_db_logs_query(
652 638 $filters,
653 639 $limit,
654 640 $offset,
@@ -655,8 +641,16 @@
655 641 $order,
656 642 true
657 643 );
658 644
645 + $upload_dir = wp_upload_dir();
646 + if ( empty( $filename ) ) {
647 + $filename = 'fs-logs-' . date( 'Y-m-d_H-i-s', WP_FS__SCRIPT_START_TIME ) . '.csv';
648 + }
649 + $filepath = rtrim( $upload_dir['path'], '/' ) . "/{$filename}";
650 +
651 + $query .= " INTO OUTFILE '{$filepath}' FIELDS TERMINATED BY '\t' ESCAPED BY '\\\\' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\\n'";
652 +
659 653 $columns = '';
660 654 for ( $i = 0, $len = count( self::$_log_columns ); $i < $len; $i ++ ) {
661 655 if ( $i > 0 ) {
662 656 $columns .= ', ';
@@ -666,18 +660,14 @@
666 660 }
667 661
668 662 $query = "SELECT {$columns} UNION ALL " . $query;
669 663
670 - $result = $GLOBALS['wpdb']->get_results( $query );
664 + $result = $wpdb->query( $query );
671 665
672 666 if ( false === $result ) {
673 667 return false;
674 668 }
675 669
676 - if ( ! self::write_csv_to_filesystem( $filepath, $result ) ) {
677 - return false;
678 - }
679 -
680 670 return rtrim( $upload_dir['url'], '/' ) . '/' . $filename;
681 671 }
682 672
683 673 /**
@@ -696,33 +686,6 @@
696 686
697 687 return rtrim( $upload_dir['url'], '/' ) . $filename;
698 688 }
699 689
700 - /**
701 - * @param string $file_path
702 - * @param array $query_results
703 - *
704 - * @return bool
705 - */
706 - private static function write_csv_to_filesystem( $file_path, $query_results ) {
707 - if ( empty( $query_results ) ) {
708 - return false;
709 - }
710 -
711 - $content = '';
712 -
713 - foreach ( $query_results as $row ) {
714 - $row_data = array_map( function ( $value ) {
715 - return str_replace( "\n", ' ', $value );
716 - }, (array) $row );
717 - $content .= implode( "\t", $row_data ) . "\n";
718 - }
719 -
720 - if ( ! $GLOBALS['wp_filesystem']->put_contents( $file_path, $content, FS_CHMOD_FILE ) ) {
721 - return false;
722 - }
723 -
724 - return true;
725 - }
726 -
727 690 #endregion
728 - }
691 + }