| @@ -16,11 +16,9 @@ | ||
| 16 | 16 | class Helper_E2pdf_Db { |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Prepare WHERE for sql requests |
| 20 | - * | |
| 21 | 20 | * @param string $condition - Array of conditions |
| 22 | - * | |
| 23 | 21 | * @return array - Filtered WHERE request |
| 24 | 22 | */ |
| 25 | 23 | public function prepare_where($condition = array(), $sub_query = false) { |
| 26 | 24 | |
| @@ -26,9 +24,9 @@ | ||
| 26 | 24 | |
| 27 | 25 | $sql = array(); |
| 28 | 26 | $filter = array(); |
| 29 | 27 | if (!$sub_query) { |
| 30 | - $sql[] = " WHERE '1' = '1'"; | |
| 28 | + $sql[] = " WHERE 1 = 1"; | |
| 31 | 29 | } |
| 32 | 30 | $condition = apply_filters('e2pdf_helper_db_prepare_where_condition', $condition); |
| 33 | 31 | |
| 34 | 32 | if (!empty($condition)) { |
| @@ -67,9 +65,9 @@ | ||
| 67 | 65 | } |
| 68 | 66 | |
| 69 | 67 | $where = array( |
| 70 | 68 | 'sql' => implode(' AND', $sql), |
| 71 | - 'filter' => $filter | |
| 69 | + 'filter' => $filter, | |
| 72 | 70 | ); |
| 73 | 71 | |
| 74 | 72 | return apply_filters('e2pdf_helper_db_prepare_where', $where, $condition); |
| 75 | 73 | } |
| @@ -75,11 +73,9 @@ | ||
| 75 | 73 | } |
| 76 | 74 | |
| 77 | 75 | /** |
| 78 | 76 | * Prepare ORDER_BY for sql requests |
| 79 | - * | |
| 80 | 77 | * @param string $condition - Array of conditions |
| 81 | - * | |
| 82 | 78 | * @return array - Filtered ORDER_BY request |
| 83 | 79 | */ |
| 84 | 80 | public function prepare_orderby($condition = array()) { |
| 85 | 81 | |
| @@ -125,9 +121,9 @@ | ||
| 125 | 121 | `title` text, |
| 126 | 122 | `created_at` datetime NOT NULL, |
| 127 | 123 | `updated_at` datetime NOT NULL, |
| 128 | 124 | `flatten` enum('0','1','2') NOT NULL DEFAULT '0', |
| 129 | - `tab_order` enum('0','1','2','3') NOT NULL DEFAULT '0', | |
| 125 | + `tab_order` enum('0','1','2','3','4') NOT NULL DEFAULT '0', | |
| 130 | 126 | `compression` int(1) NOT NULL DEFAULT '-1', |
| 131 | 127 | `optimization` int(1) NOT NULL DEFAULT '-1', |
| 132 | 128 | `appearance` enum('0','1') NOT NULL DEFAULT '0', |
| 133 | 129 | `width` int(11) NOT NULL DEFAULT '0', |
| @@ -163,8 +159,9 @@ | ||
| 163 | 159 | `font_color` varchar(255) NOT NULL, |
| 164 | 160 | `line_height` varchar(255) NOT NULL, |
| 165 | 161 | `text_align` varchar(255) NOT NULL, |
| 166 | 162 | `fonts` longtext NOT NULL, |
| 163 | + `attachments` longtext NOT NULL, | |
| 167 | 164 | `trash` enum('0','1') NOT NULL DEFAULT '0', |
| 168 | 165 | `activated` enum('0','1') NOT NULL DEFAULT '0', |
| 169 | 166 | `locked` enum('0','1') NOT NULL DEFAULT '0', |
| 170 | 167 | `author` int(11) NOT NULL, |
| @@ -193,9 +190,9 @@ | ||
| 193 | 190 | $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_templates` ADD COLUMN `meta_keywords` text NOT NULL AFTER meta_author;"); |
| 194 | 191 | } |
| 195 | 192 | |
| 196 | 193 | if (!$wpdb->get_var("SHOW COLUMNS FROM `" . $db_prefix . "e2pdf_templates` LIKE 'lang_code';")) { |
| 197 | - $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_templates` ADD COLUMN `lang_code` text NOT NULL AFTER meta_keywords;"); | |
| 194 | + $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_templates` ADD COLUMN `lang_code` varchar(255) NOT NULL AFTER meta_keywords;"); | |
| 198 | 195 | } |
| 199 | 196 | |
| 200 | 197 | if (!$wpdb->get_var("SHOW COLUMNS FROM `" . $db_prefix . "e2pdf_templates` LIKE 'actions';")) { |
| 201 | 198 | $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_templates` ADD COLUMN `actions` longtext NOT NULL AFTER author;"); |
| @@ -220,10 +217,13 @@ | ||
| 220 | 217 | if (!$wpdb->get_var("SHOW COLUMNS FROM `" . $db_prefix . "e2pdf_templates` LIKE 'text_align';")) { |
| 221 | 218 | $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_templates` ADD COLUMN `text_align` varchar(255) NOT NULL AFTER line_height;"); |
| 222 | 219 | } |
| 223 | 220 | |
| 224 | - if (!$wpdb->get_var("SHOW COLUMNS FROM `" . $db_prefix . "e2pdf_templates` LIKE 'tab_order';")) { | |
| 225 | - $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_templates` ADD COLUMN `tab_order` enum('0','1','2','3') NOT NULL DEFAULT '0' AFTER flatten;"); | |
| 221 | + $tab_order = $wpdb->get_var("SHOW COLUMNS FROM `" . $db_prefix . "e2pdf_templates` LIKE 'tab_order';", 1); | |
| 222 | + if ($tab_order === null) { | |
| 223 | + $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_templates` ADD COLUMN `tab_order` enum('0','1','2','3','4') NOT NULL DEFAULT '0' AFTER flatten;"); | |
| 224 | + } elseif (strpos($tab_order, "'4'") === false) { | |
| 225 | + $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_templates` MODIFY COLUMN `tab_order` enum('0','1','2','3','4') NOT NULL DEFAULT '0';"); | |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | if (!$wpdb->get_var("SHOW COLUMNS FROM `" . $db_prefix . "e2pdf_templates` LIKE 'item1';")) { |
| 229 | 229 | $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_templates` ADD COLUMN `item1` varchar(255) NOT NULL AFTER item;"); |
| @@ -418,9 +418,9 @@ | ||
| 418 | 418 | `title` text, |
| 419 | 419 | `created_at` datetime NOT NULL, |
| 420 | 420 | `updated_at` datetime NOT NULL, |
| 421 | 421 | `flatten` enum('0','1','2') NOT NULL DEFAULT '0', |
| 422 | - `tab_order` enum('0','1','2','3') NOT NULL DEFAULT '0', | |
| 422 | + `tab_order` enum('0','1','2','3','4') NOT NULL DEFAULT '0', | |
| 423 | 423 | `compression` int(1) NOT NULL DEFAULT '-1', |
| 424 | 424 | `optimization` int(1) NOT NULL DEFAULT '-1', |
| 425 | 425 | `appearance` enum('0','1') NOT NULL DEFAULT '0', |
| 426 | 426 | `width` int(11) NOT NULL DEFAULT '0', |
| @@ -456,8 +456,9 @@ | ||
| 456 | 456 | `font_color` varchar(255) NOT NULL, |
| 457 | 457 | `line_height` varchar(255) NOT NULL, |
| 458 | 458 | `text_align` varchar(255) NOT NULL, |
| 459 | 459 | `fonts` longtext NOT NULL, |
| 460 | + `attachments` longtext NOT NULL, | |
| 460 | 461 | `author` int(11) NOT NULL, |
| 461 | 462 | `properties` longtext NOT NULL, |
| 462 | 463 | `actions` longtext NOT NULL, |
| 463 | 464 | PRIMARY KEY (`PID`) |
| @@ -473,9 +474,9 @@ | ||
| 473 | 474 | $wpdb->query("CREATE INDEX `template_id` ON `" . $db_prefix . "e2pdf_revisions` (`template_id`);"); |
| 474 | 475 | } |
| 475 | 476 | |
| 476 | 477 | if (!$wpdb->get_var("SHOW COLUMNS FROM `" . $db_prefix . "e2pdf_revisions` LIKE 'lang_code';")) { |
| 477 | - $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_revisions` ADD COLUMN `lang_code` text NOT NULL AFTER meta_keywords;"); | |
| 478 | + $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_revisions` ADD COLUMN `lang_code` varchar(255) NOT NULL AFTER meta_keywords;"); | |
| 478 | 479 | } |
| 479 | 480 | |
| 480 | 481 | if (!$wpdb->get_var("SHOW COLUMNS FROM `" . $db_prefix . "e2pdf_revisions` LIKE 'actions';")) { |
| 481 | 482 | $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_revisions` ADD COLUMN `actions` longtext NOT NULL AFTER author;"); |
| @@ -500,10 +501,13 @@ | ||
| 500 | 501 | if (!$wpdb->get_var("SHOW COLUMNS FROM `" . $db_prefix . "e2pdf_revisions` LIKE 'text_align';")) { |
| 501 | 502 | $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_revisions` ADD COLUMN `text_align` varchar(255) NOT NULL AFTER line_height;"); |
| 502 | 503 | } |
| 503 | 504 | |
| 504 | - if (!$wpdb->get_var("SHOW COLUMNS FROM `" . $db_prefix . "e2pdf_revisions` LIKE 'tab_order';")) { | |
| 505 | - $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_revisions` ADD COLUMN `tab_order` enum('0','1','2','3') NOT NULL DEFAULT '0' AFTER flatten;"); | |
| 505 | + $tab_order = $wpdb->get_var("SHOW COLUMNS FROM `" . $db_prefix . "e2pdf_revisions` LIKE 'tab_order';", 1); | |
| 506 | + if ($tab_order === null) { | |
| 507 | + $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_revisions` ADD COLUMN `tab_order` enum('0','1','2','3','4') NOT NULL DEFAULT '0' AFTER flatten;"); | |
| 508 | + } elseif (strpos($tab_order, "'4'") === false) { | |
| 509 | + $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_revisions` MODIFY COLUMN `tab_order` enum('0','1','2','3','4') NOT NULL DEFAULT '0';"); | |
| 506 | 510 | } |
| 507 | 511 | |
| 508 | 512 | if (!$wpdb->get_var("SHOW COLUMNS FROM `" . $db_prefix . "e2pdf_revisions` LIKE 'item1';")) { |
| 509 | 513 | $wpdb->query("ALTER TABLE `" . $db_prefix . "e2pdf_revisions` ADD COLUMN `item1` varchar(255) NOT NULL AFTER item;"); |
| @@ -686,19 +690,19 @@ | ||
| 686 | 690 | $condition = array( |
| 687 | 691 | 'TABLE_SCHEMA' => array( |
| 688 | 692 | 'condition' => '=', |
| 689 | 693 | 'value' => DB_NAME, |
| 690 | - 'type' => '%s' | |
| 694 | + 'type' => '%s', | |
| 691 | 695 | ), |
| 692 | 696 | 'TABLE_NAME' => array( |
| 693 | 697 | 'condition' => '=', |
| 694 | 698 | 'value' => $db_prefix . $table, |
| 695 | - 'type' => '%s' | |
| 699 | + 'type' => '%s', | |
| 696 | 700 | ), |
| 697 | 701 | 'TABLE_COLLATION' => array( |
| 698 | 702 | 'condition' => '=', |
| 699 | 703 | 'value' => $wpdb->collate, |
| 700 | - 'type' => '%s' | |
| 704 | + 'type' => '%s', | |
| 701 | 705 | ), |
| 702 | 706 | ); |
| 703 | 707 | $where = $this->prepare_where($condition); |
| 704 | 708 | $check = $wpdb->get_var($wpdb->prepare('SELECT COUNT(*) FROM `INFORMATION_SCHEMA`.`TABLES` ' . $where['sql'] . '', $where['filter'])); |
| @@ -769,9 +773,9 @@ | ||
| 769 | 773 | 'locked' => array(), |
| 770 | 774 | 'author' => array(), |
| 771 | 775 | 'properties' => array(), |
| 772 | 776 | 'actions' => array(), |
| 773 | - ) | |
| 777 | + ), | |
| 774 | 778 | ), |
| 775 | 779 | 'e2pdf_entries' => array( |
| 776 | 780 | 'format' => __('Undefined', 'e2pdf'), |
| 777 | 781 | 'check' => false, |
| @@ -779,9 +783,9 @@ | ||
| 779 | 783 | 'ID' => array(), |
| 780 | 784 | 'uid' => array(), |
| 781 | 785 | 'entry' => array(), |
| 782 | 786 | 'pdf_num' => array(), |
| 783 | - ) | |
| 787 | + ), | |
| 784 | 788 | ), |
| 785 | 789 | 'e2pdf_datasets' => array( |
| 786 | 790 | 'format' => '', |
| 787 | 791 | 'check' => false, |
| @@ -790,9 +794,9 @@ | ||
| 790 | 794 | 'extension' => array(), |
| 791 | 795 | 'item' => array(), |
| 792 | 796 | 'entry' => array(), |
| 793 | 797 | 'created_at' => array(), |
| 794 | - ) | |
| 798 | + ), | |
| 795 | 799 | ), |
| 796 | 800 | 'e2pdf_pages' => array( |
| 797 | 801 | 'format' => __('Undefined', 'e2pdf'), |
| 798 | 802 | 'check' => false, |
| @@ -802,9 +806,9 @@ | ||
| 802 | 806 | 'template_id' => array(), |
| 803 | 807 | 'properties' => array(), |
| 804 | 808 | 'actions' => array(), |
| 805 | 809 | 'revision_id' => array(), |
| 806 | - ) | |
| 810 | + ), | |
| 807 | 811 | ), |
| 808 | 812 | 'e2pdf_elements' => array( |
| 809 | 813 | 'format' => __('Undefined', 'e2pdf'), |
| 810 | 814 | 'check' => false, |
| @@ -822,9 +826,9 @@ | ||
| 822 | 826 | 'value' => array(), |
| 823 | 827 | 'properties' => array(), |
| 824 | 828 | 'actions' => array(), |
| 825 | 829 | 'revision_id' => array(), |
| 826 | - ) | |
| 830 | + ), | |
| 827 | 831 | ), |
| 828 | 832 | 'e2pdf_revisions' => array( |
| 829 | 833 | 'format' => __('Undefined', 'e2pdf'), |
| 830 | 834 | 'check' => false, |
| @@ -878,10 +882,26 @@ | ||
| 878 | 882 | 'attachments' => array(), |
| 879 | 883 | 'author' => array(), |
| 880 | 884 | 'properties' => array(), |
| 881 | 885 | 'actions' => array(), |
| 882 | - ) | |
| 883 | - ) | |
| 886 | + ), | |
| 887 | + ), | |
| 888 | + 'e2pdf_bulks' => array( | |
| 889 | + 'format' => __('Undefined', 'e2pdf'), | |
| 890 | + 'check' => false, | |
| 891 | + 'columns' => array( | |
| 892 | + 'ID' => array(), | |
| 893 | + 'uid' => array(), | |
| 894 | + 'template_id' => array(), | |
| 895 | + 'count' => array(), | |
| 896 | + 'total' => array(), | |
| 897 | + 'dataset' => array(), | |
| 898 | + 'datasets' => array(), | |
| 899 | + 'options' => array(), | |
| 900 | + 'status' => array(), | |
| 901 | + 'created_at' => array(), | |
| 902 | + ), | |
| 903 | + ), | |
| 884 | 904 | ); |
| 885 | 905 | |
| 886 | 906 | if ($check) { |
| 887 | 907 | foreach ($db_structure as $table_key => $table) { |
| @@ -888,14 +908,14 @@ | ||
| 888 | 908 | $condition = array( |
| 889 | 909 | 'TABLE_SCHEMA' => array( |
| 890 | 910 | 'condition' => '=', |
| 891 | 911 | 'value' => DB_NAME, |
| 892 | - 'type' => '%s' | |
| 912 | + 'type' => '%s', | |
| 893 | 913 | ), |
| 894 | 914 | 'TABLE_NAME' => array( |
| 895 | 915 | 'condition' => '=', |
| 896 | 916 | 'value' => $db_prefix . $table_key, |
| 897 | - 'type' => '%s' | |
| 917 | + 'type' => '%s', | |
| 898 | 918 | ), |
| 899 | 919 | ); |
| 900 | 920 | $where = $this->prepare_where($condition); |
| 901 | 921 | $table_exists = $wpdb->get_var($wpdb->prepare('SELECT COUNT(*) FROM `INFORMATION_SCHEMA`.`TABLES` ' . $where['sql'] . '', $where['filter'])); |