PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 1.2.5
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v1.2.5
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
← All changes | app/src/Models/DatabaseModel.php +12 -85 4.2.21.2.5 View file →
@@ -4,8 +4,9 @@
4 4
5 5 use ArrayAccess;
6 6 use JsonSerializable;
7 7 use SureCart\Concerns\Arrayable;
8 +use SureCartVendors\PluginEver\QueryBuilder\Collection;
8 9 use SureCartVendors\PluginEver\QueryBuilder\Query;
9 10
10 11 /**
11 12 * Model class
@@ -398,11 +399,13 @@
398 399 }
399 400
400 401 // set attribute.
401 402 if ( ! $is_guarded ) {
402 - $this->setAttribute( $key, maybe_unserialize( maybe_unserialize( $value ) ) );
403 - } elseif ( $this->isFillable( $key ) ) {
404 - $this->setAttribute( $key, maybe_unserialize( maybe_unserialize( $value ) ) );
403 + $this->setAttribute( $key, $value );
404 + } else {
405 + if ( $this->isFillable( $key ) ) {
406 + $this->setAttribute( $key, $value );
407 + }
405 408 }
406 409 }
407 410
408 411 return apply_filters( "surecart/{$this->object_name}/set_attributes", $this );
@@ -552,15 +555,10 @@
552 555 ]
553 556 );
554 557
555 558 $this->query = $this->getQuery();
559 + $this->query->page( $args['page'], $args['per_page'] );
556 560
557 - $size = (int) $args['per_page'];
558 - $limit = (int) $size;
559 - $offset = (int) $size * ( ( (int) $args['page'] ) - 1 );
560 -
561 - $this->query->limit( $offset, $limit );
562 -
563 561 return $this;
564 562 }
565 563
566 564 /**
@@ -711,19 +709,9 @@
711 709 $this->syncOriginal();
712 710 $this->fill( $attributes );
713 711 }
714 712
715 - $id = $this->getQuery()->insert(
716 - array_merge(
717 - [ 'created_at' => current_time( 'mysql' ) ],
718 - array_map(
719 - function ( $item ) {
720 - return maybe_serialize( $item );
721 - },
722 - $this->attributes
723 - )
724 - )
725 - );
713 + $id = $this->getQuery()->insert( array_merge( [ 'created_at' => current_time( 'mysql' ) ], $this->attributes ) );
726 714 if ( ! $id ) {
727 715 return new \WP_Error( 'could_not_create', 'Could not create.' );
728 716 }
729 717
@@ -767,19 +755,9 @@
767 755 if ( is_wp_error( $item ) ) {
768 756 return $item;
769 757 }
770 758
771 - $update = $this->getQuery()->where( 'id', $item->id )->update(
772 - array_merge(
773 - [ 'updated_at' => current_time( 'mysql' ) ],
774 - array_map(
775 - function ( $item ) {
776 - return maybe_serialize( $item );
777 - },
778 - $attributes
779 - )
780 - )
781 - );
759 + $update = $this->getQuery()->where( 'id', $item->id )->update( array_merge( [ 'updated_at' => current_time( 'mysql' ) ], $attributes ) );
782 760 if ( false === $update ) {
783 761 return new \WP_Error( 'could_not_update', 'Could not update.' );
784 762 }
785 763
@@ -809,18 +787,9 @@
809 787 if ( $this->fireModelEvent( 'deleting' ) === false ) {
810 788 return false;
811 789 }
812 790
813 - $delete = $this->getQuery();
814 -
815 - // deleting a single.
816 - if ( $id ) {
817 - $delete = $delete->where( 'ID', $id );
818 - }
819 -
820 - // delete.
821 - $deleted = $delete->delete();
822 -
791 + $deleted = $this->getQuery()->where( 'ID', $id )->delete();
823 792 if ( false === $deleted ) {
824 793 return new \WP_Error( 'could_not_delete', 'Could not delete.' );
825 794 }
826 795
@@ -829,22 +798,8 @@
829 798 return $deleted;
830 799 }
831 800
832 801 /**
833 - * Delete all items.
834 - *
835 - * @return $this|false
836 - */
837 - protected function deleteAll() {
838 - $delete = $this->getQuery();
839 - $deleted = $delete->delete();
840 - if ( false === $deleted ) {
841 - return new \WP_Error( 'could_not_delete', 'Could not delete.' );
842 - }
843 - return $deleted;
844 - }
845 -
846 - /**
847 802 * Set a model relation.
848 803 *
849 804 * @prop string $attribute Attribute name.
850 805 * @prop string $value Value to set.
@@ -933,9 +888,9 @@
933 888
934 889 /**
935 890 * Calls accessors during toArray.
936 891 *
937 - * @return array
892 + * @return Array
938 893 */
939 894 public function toArray() {
940 895 $attributes = $this->getAttributes();
941 896
@@ -940,9 +895,9 @@
940 895 $attributes = $this->getAttributes();
941 896
942 897 // Check if any accessor is available and call it.
943 898 foreach ( get_class_methods( $this ) as $method ) {
944 - if ( ! method_exists( get_class( $this ), $method ) ) {
899 + if ( method_exists( get_class(), $method ) ) {
945 900 continue;
946 901 }
947 902
948 903 if ( 'get' === substr( $method, 0, 3 ) && 'Attribute' === substr( $method, -9 ) ) {
@@ -1143,9 +1098,8 @@
1143 1098 return call_user_func_array( [ $this, $method ], $params );
1144 1099 }
1145 1100 // if the query builder has a method, start building query.
1146 1101 if ( method_exists( Query::class, $method ) ) {
1147 - $params = $this->filterWhereColumns( $method, $params );
1148 1102 $result = $this->getQuery()->{$method}( ...$params );
1149 1103 if ( in_array( $method, [ 'count' ] ) ) {
1150 1104 return $result;
1151 1105 }
@@ -1169,9 +1123,8 @@
1169 1123
1170 1124 // if the query builder has a method, start building query.
1171 1125 if ( method_exists( Query::class, $method ) ) {
1172 1126 $item = new static();
1173 - $params = $item->filterWhereColumns( $method, $params );
1174 1127 $result = $item->getQuery()->{$method}( ...$params );
1175 1128 if ( in_array( $method, [ 'count' ] ) ) {
1176 1129 return $result;
1177 1130 }
@@ -1176,32 +1129,6 @@
1176 1129 return $result;
1177 1130 }
1178 1131 return $item;
1179 1132 }
1180 - }
1181 -
1182 - /**
1183 - * Filter out non-fillable column names from an associative `where()` argument.
1184 - *
1185 - * The query builder uses array keys as raw SQL column identifiers in its
1186 - * `where( [ 'col' => 'value' ] )` form. `$wpdb->prepare()` cannot escape
1187 - * identifiers, so untrusted keys must be restricted to known fields before
1188 - * reaching the builder.
1189 - *
1190 - * @param string $method Forwarded method name.
1191 - * @param array $params Forwarded parameters.
1192 - * @return array
1193 - */
1194 - protected function filterWhereColumns( $method, $params ) {
1195 - if ( ! in_array( $method, ['where', 'orWhere', 'andWhere'], true ) ) {
1196 - return $params;
1197 - }
1198 - if ( empty( $params ) || ! is_array( $params[0] ) ) {
1199 - return $params;
1200 - }
1201 - if ( [ '*' ] === $this->fillable ) {
1202 - return $params;
1203 - }
1204 - $params[0] = array_intersect_key( $params[0], array_flip( $this->fillable ) );
1205 - return $params;
1206 1133 }
1207 1134 }