@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function __construct() |
26 | 26 | { |
27 | - $this->setName($this->namespace . 'TicketsConnectionOrderbyInput'); |
|
27 | + $this->setName($this->namespace.'TicketsConnectionOrderbyInput'); |
|
28 | 28 | $this->setDescription(esc_html__('Options for ordering the connection', 'event_espresso')); |
29 | 29 | parent::__construct(); |
30 | 30 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | return [ |
40 | 40 | new GraphQLField( |
41 | 41 | 'field', |
42 | - ['non_null' => $this->namespace . 'TicketsConnectionOrderbyEnum'] |
|
42 | + ['non_null' => $this->namespace.'TicketsConnectionOrderbyEnum'] |
|
43 | 43 | ), |
44 | 44 | new GraphQLField( |
45 | 45 | 'order', |
@@ -17,31 +17,31 @@ |
||
17 | 17 | class TicketsConnectionOrderbyInput extends InputBase |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * TicketsConnectionOrderbyInput constructor. |
|
22 | - */ |
|
23 | - public function __construct() |
|
24 | - { |
|
25 | - $this->setName($this->namespace . 'TicketsConnectionOrderbyInput'); |
|
26 | - $this->setDescription(esc_html__('Options for ordering the connection', 'event_espresso')); |
|
27 | - parent::__construct(); |
|
28 | - } |
|
20 | + /** |
|
21 | + * TicketsConnectionOrderbyInput constructor. |
|
22 | + */ |
|
23 | + public function __construct() |
|
24 | + { |
|
25 | + $this->setName($this->namespace . 'TicketsConnectionOrderbyInput'); |
|
26 | + $this->setDescription(esc_html__('Options for ordering the connection', 'event_espresso')); |
|
27 | + parent::__construct(); |
|
28 | + } |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * @return GraphQLFieldInterface[] |
|
33 | - */ |
|
34 | - protected function getFields(): array |
|
35 | - { |
|
36 | - return [ |
|
37 | - new GraphQLField( |
|
38 | - 'field', |
|
39 | - ['non_null' => $this->namespace . 'TicketsConnectionOrderbyEnum'] |
|
40 | - ), |
|
41 | - new GraphQLField( |
|
42 | - 'order', |
|
43 | - 'OrderEnum' |
|
44 | - ), |
|
45 | - ]; |
|
46 | - } |
|
31 | + /** |
|
32 | + * @return GraphQLFieldInterface[] |
|
33 | + */ |
|
34 | + protected function getFields(): array |
|
35 | + { |
|
36 | + return [ |
|
37 | + new GraphQLField( |
|
38 | + 'field', |
|
39 | + ['non_null' => $this->namespace . 'TicketsConnectionOrderbyEnum'] |
|
40 | + ), |
|
41 | + new GraphQLField( |
|
42 | + 'order', |
|
43 | + 'OrderEnum' |
|
44 | + ), |
|
45 | + ]; |
|
46 | + } |
|
47 | 47 | } |
@@ -38,8 +38,8 @@ |
||
38 | 38 | { |
39 | 39 | return [ |
40 | 40 | 'fromType' => 'RootQuery', |
41 | - 'toType' => $this->namespace . 'Price', |
|
42 | - 'fromFieldName' => lcfirst($this->namespace) . 'Prices', |
|
41 | + 'toType' => $this->namespace.'Price', |
|
42 | + 'fromFieldName' => lcfirst($this->namespace).'Prices', |
|
43 | 43 | 'connectionTypeName' => "{$this->namespace}RootQueryPricesConnection", |
44 | 44 | 'connectionArgs' => TicketPricesConnection::get_connection_args(), |
45 | 45 | 'resolve' => [$this, 'resolveConnection'], |
@@ -20,43 +20,43 @@ |
||
20 | 20 | { |
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * PriceConnection constructor. |
|
25 | - * |
|
26 | - * @param EEM_Price $model |
|
27 | - */ |
|
28 | - public function __construct(EEM_Price $model) |
|
29 | - { |
|
30 | - parent::__construct($model); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @return array |
|
36 | - */ |
|
37 | - public function config(): array |
|
38 | - { |
|
39 | - return [ |
|
40 | - 'fromType' => 'RootQuery', |
|
41 | - 'toType' => $this->namespace . 'Price', |
|
42 | - 'fromFieldName' => lcfirst($this->namespace) . 'Prices', |
|
43 | - 'connectionTypeName' => "{$this->namespace}RootQueryPricesConnection", |
|
44 | - 'connectionArgs' => TicketPricesConnection::get_connection_args(), |
|
45 | - 'resolve' => [$this, 'resolveConnection'], |
|
46 | - ]; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * @param $entity |
|
52 | - * @param $args |
|
53 | - * @param $context |
|
54 | - * @param $info |
|
55 | - * @return PriceConnectionResolver |
|
56 | - * @throws Exception |
|
57 | - */ |
|
58 | - public function getConnectionResolver($entity, $args, $context, $info): AbstractConnectionResolver |
|
59 | - { |
|
60 | - return new PriceConnectionResolver($entity, $args, $context, $info); |
|
61 | - } |
|
23 | + /** |
|
24 | + * PriceConnection constructor. |
|
25 | + * |
|
26 | + * @param EEM_Price $model |
|
27 | + */ |
|
28 | + public function __construct(EEM_Price $model) |
|
29 | + { |
|
30 | + parent::__construct($model); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @return array |
|
36 | + */ |
|
37 | + public function config(): array |
|
38 | + { |
|
39 | + return [ |
|
40 | + 'fromType' => 'RootQuery', |
|
41 | + 'toType' => $this->namespace . 'Price', |
|
42 | + 'fromFieldName' => lcfirst($this->namespace) . 'Prices', |
|
43 | + 'connectionTypeName' => "{$this->namespace}RootQueryPricesConnection", |
|
44 | + 'connectionArgs' => TicketPricesConnection::get_connection_args(), |
|
45 | + 'resolve' => [$this, 'resolveConnection'], |
|
46 | + ]; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * @param $entity |
|
52 | + * @param $args |
|
53 | + * @param $context |
|
54 | + * @param $info |
|
55 | + * @return PriceConnectionResolver |
|
56 | + * @throws Exception |
|
57 | + */ |
|
58 | + public function getConnectionResolver($entity, $args, $context, $info): AbstractConnectionResolver |
|
59 | + { |
|
60 | + return new PriceConnectionResolver($entity, $args, $context, $info); |
|
61 | + } |
|
62 | 62 | } |
@@ -38,8 +38,8 @@ |
||
38 | 38 | { |
39 | 39 | return [ |
40 | 40 | 'fromType' => 'RootQuery', |
41 | - 'toType' => $this->namespace . 'Datetime', |
|
42 | - 'fromFieldName' => lcfirst($this->namespace . 'Datetimes'), |
|
41 | + 'toType' => $this->namespace.'Datetime', |
|
42 | + 'fromFieldName' => lcfirst($this->namespace.'Datetimes'), |
|
43 | 43 | 'connectionTypeName' => "{$this->namespace}RootQueryDatetimesConnection", |
44 | 44 | 'connectionArgs' => EventDatetimesConnection::get_connection_args(), |
45 | 45 | 'resolve' => [$this, 'resolveConnection'], |
@@ -20,43 +20,43 @@ |
||
20 | 20 | { |
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * DatetimeConnection constructor. |
|
25 | - * |
|
26 | - * @param EEM_Datetime $model |
|
27 | - */ |
|
28 | - public function __construct(EEM_Datetime $model) |
|
29 | - { |
|
30 | - parent::__construct($model); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @return array |
|
36 | - */ |
|
37 | - public function config(): array |
|
38 | - { |
|
39 | - return [ |
|
40 | - 'fromType' => 'RootQuery', |
|
41 | - 'toType' => $this->namespace . 'Datetime', |
|
42 | - 'fromFieldName' => lcfirst($this->namespace . 'Datetimes'), |
|
43 | - 'connectionTypeName' => "{$this->namespace}RootQueryDatetimesConnection", |
|
44 | - 'connectionArgs' => EventDatetimesConnection::get_connection_args(), |
|
45 | - 'resolve' => [$this, 'resolveConnection'], |
|
46 | - ]; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * @param $entity |
|
52 | - * @param $args |
|
53 | - * @param $context |
|
54 | - * @param $info |
|
55 | - * @return DatetimeConnectionResolver |
|
56 | - * @throws Exception |
|
57 | - */ |
|
58 | - public function getConnectionResolver($entity, $args, $context, $info): AbstractConnectionResolver |
|
59 | - { |
|
60 | - return new DatetimeConnectionResolver($entity, $args, $context, $info); |
|
61 | - } |
|
23 | + /** |
|
24 | + * DatetimeConnection constructor. |
|
25 | + * |
|
26 | + * @param EEM_Datetime $model |
|
27 | + */ |
|
28 | + public function __construct(EEM_Datetime $model) |
|
29 | + { |
|
30 | + parent::__construct($model); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @return array |
|
36 | + */ |
|
37 | + public function config(): array |
|
38 | + { |
|
39 | + return [ |
|
40 | + 'fromType' => 'RootQuery', |
|
41 | + 'toType' => $this->namespace . 'Datetime', |
|
42 | + 'fromFieldName' => lcfirst($this->namespace . 'Datetimes'), |
|
43 | + 'connectionTypeName' => "{$this->namespace}RootQueryDatetimesConnection", |
|
44 | + 'connectionArgs' => EventDatetimesConnection::get_connection_args(), |
|
45 | + 'resolve' => [$this, 'resolveConnection'], |
|
46 | + ]; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * @param $entity |
|
52 | + * @param $args |
|
53 | + * @param $context |
|
54 | + * @param $info |
|
55 | + * @return DatetimeConnectionResolver |
|
56 | + * @throws Exception |
|
57 | + */ |
|
58 | + public function getConnectionResolver($entity, $args, $context, $info): AbstractConnectionResolver |
|
59 | + { |
|
60 | + return new DatetimeConnectionResolver($entity, $args, $context, $info); |
|
61 | + } |
|
62 | 62 | } |
@@ -38,8 +38,8 @@ |
||
38 | 38 | { |
39 | 39 | return [ |
40 | 40 | 'fromType' => 'RootQuery', |
41 | - 'toType' => $this->namespace . 'Ticket', |
|
42 | - 'fromFieldName' => lcfirst($this->namespace) . 'Tickets', |
|
41 | + 'toType' => $this->namespace.'Ticket', |
|
42 | + 'fromFieldName' => lcfirst($this->namespace).'Tickets', |
|
43 | 43 | 'connectionTypeName' => "{$this->namespace}RootQueryTicketsConnection", |
44 | 44 | 'connectionArgs' => DatetimeTicketsConnection::get_connection_args(), |
45 | 45 | 'resolve' => [$this, 'resolveConnection'], |
@@ -20,43 +20,43 @@ |
||
20 | 20 | { |
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * TicketConnection constructor. |
|
25 | - * |
|
26 | - * @param EEM_Ticket $model |
|
27 | - */ |
|
28 | - public function __construct(EEM_Ticket $model) |
|
29 | - { |
|
30 | - parent::__construct($model); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @return array |
|
36 | - */ |
|
37 | - public function config(): array |
|
38 | - { |
|
39 | - return [ |
|
40 | - 'fromType' => 'RootQuery', |
|
41 | - 'toType' => $this->namespace . 'Ticket', |
|
42 | - 'fromFieldName' => lcfirst($this->namespace) . 'Tickets', |
|
43 | - 'connectionTypeName' => "{$this->namespace}RootQueryTicketsConnection", |
|
44 | - 'connectionArgs' => DatetimeTicketsConnection::get_connection_args(), |
|
45 | - 'resolve' => [$this, 'resolveConnection'], |
|
46 | - ]; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * @param $entity |
|
52 | - * @param $args |
|
53 | - * @param $context |
|
54 | - * @param $info |
|
55 | - * @return TicketConnectionResolver |
|
56 | - * @throws Exception |
|
57 | - */ |
|
58 | - public function getConnectionResolver($entity, $args, $context, $info): AbstractConnectionResolver |
|
59 | - { |
|
60 | - return new TicketConnectionResolver($entity, $args, $context, $info); |
|
61 | - } |
|
23 | + /** |
|
24 | + * TicketConnection constructor. |
|
25 | + * |
|
26 | + * @param EEM_Ticket $model |
|
27 | + */ |
|
28 | + public function __construct(EEM_Ticket $model) |
|
29 | + { |
|
30 | + parent::__construct($model); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @return array |
|
36 | + */ |
|
37 | + public function config(): array |
|
38 | + { |
|
39 | + return [ |
|
40 | + 'fromType' => 'RootQuery', |
|
41 | + 'toType' => $this->namespace . 'Ticket', |
|
42 | + 'fromFieldName' => lcfirst($this->namespace) . 'Tickets', |
|
43 | + 'connectionTypeName' => "{$this->namespace}RootQueryTicketsConnection", |
|
44 | + 'connectionArgs' => DatetimeTicketsConnection::get_connection_args(), |
|
45 | + 'resolve' => [$this, 'resolveConnection'], |
|
46 | + ]; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * @param $entity |
|
52 | + * @param $args |
|
53 | + * @param $context |
|
54 | + * @param $info |
|
55 | + * @return TicketConnectionResolver |
|
56 | + * @throws Exception |
|
57 | + */ |
|
58 | + public function getConnectionResolver($entity, $args, $context, $info): AbstractConnectionResolver |
|
59 | + { |
|
60 | + return new TicketConnectionResolver($entity, $args, $context, $info); |
|
61 | + } |
|
62 | 62 | } |
@@ -47,7 +47,7 @@ |
||
47 | 47 | { |
48 | 48 | return [ |
49 | 49 | new GraphQLOutputField( |
50 | - lcfirst($this->namespace) . 'EventRelations', |
|
50 | + lcfirst($this->namespace).'EventRelations', |
|
51 | 51 | 'String', |
52 | 52 | null, |
53 | 53 | esc_html__('JSON encoded relational data of the models', 'event_espresso'), |
@@ -27,72 +27,72 @@ |
||
27 | 27 | class RootQuery extends TypeBase |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * RootQuery constructor. |
|
32 | - */ |
|
33 | - public function __construct() |
|
34 | - { |
|
35 | - $this->setName('RootQuery'); |
|
36 | - $this->setIsCustomPostType(true); |
|
37 | - parent::__construct(); |
|
38 | - } |
|
30 | + /** |
|
31 | + * RootQuery constructor. |
|
32 | + */ |
|
33 | + public function __construct() |
|
34 | + { |
|
35 | + $this->setName('RootQuery'); |
|
36 | + $this->setIsCustomPostType(true); |
|
37 | + parent::__construct(); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @return GraphQLFieldInterface[] |
|
43 | - */ |
|
44 | - public function getFields(): array |
|
45 | - { |
|
46 | - return [ |
|
47 | - new GraphQLOutputField( |
|
48 | - lcfirst($this->namespace) . 'EventRelations', |
|
49 | - 'String', |
|
50 | - null, |
|
51 | - esc_html__('JSON encoded relational data of the models', 'event_espresso'), |
|
52 | - null, |
|
53 | - [$this, 'getEventRelationalData'], |
|
54 | - [ |
|
55 | - 'eventId' => [ |
|
56 | - 'type' => ['non_null' => 'Int'], |
|
57 | - 'description' => esc_html__('The event ID to get the relational data for.', 'event_espresso'), |
|
58 | - ], |
|
59 | - ] |
|
60 | - ), |
|
61 | - ]; |
|
62 | - } |
|
41 | + /** |
|
42 | + * @return GraphQLFieldInterface[] |
|
43 | + */ |
|
44 | + public function getFields(): array |
|
45 | + { |
|
46 | + return [ |
|
47 | + new GraphQLOutputField( |
|
48 | + lcfirst($this->namespace) . 'EventRelations', |
|
49 | + 'String', |
|
50 | + null, |
|
51 | + esc_html__('JSON encoded relational data of the models', 'event_espresso'), |
|
52 | + null, |
|
53 | + [$this, 'getEventRelationalData'], |
|
54 | + [ |
|
55 | + 'eventId' => [ |
|
56 | + 'type' => ['non_null' => 'Int'], |
|
57 | + 'description' => esc_html__('The event ID to get the relational data for.', 'event_espresso'), |
|
58 | + ], |
|
59 | + ] |
|
60 | + ), |
|
61 | + ]; |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
67 | - * @param array $args The inputArgs on the field |
|
68 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
69 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
70 | - * @return string |
|
71 | - * @throws Exception |
|
72 | - * @throws InvalidArgumentException |
|
73 | - * @throws InvalidDataTypeException |
|
74 | - * @throws InvalidInterfaceException |
|
75 | - * @throws UserError |
|
76 | - * @throws UnexpectedEntityException |
|
77 | - * @since $VID:$ |
|
78 | - */ |
|
79 | - public function getEventRelationalData($source, array $args, AppContext $context, ResolveInfo $info): string |
|
80 | - { |
|
81 | - /** |
|
82 | - * Throw an exception if there's no event ID |
|
83 | - */ |
|
84 | - if (empty($args['eventId']) || ! absint($args['eventId'])) { |
|
85 | - throw new UserError(esc_html__( |
|
86 | - 'No event ID was provided to get the relational data for', |
|
87 | - 'event_espresso' |
|
88 | - )); |
|
89 | - } |
|
65 | + /** |
|
66 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
67 | + * @param array $args The inputArgs on the field |
|
68 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
69 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
70 | + * @return string |
|
71 | + * @throws Exception |
|
72 | + * @throws InvalidArgumentException |
|
73 | + * @throws InvalidDataTypeException |
|
74 | + * @throws InvalidInterfaceException |
|
75 | + * @throws UserError |
|
76 | + * @throws UnexpectedEntityException |
|
77 | + * @since $VID:$ |
|
78 | + */ |
|
79 | + public function getEventRelationalData($source, array $args, AppContext $context, ResolveInfo $info): string |
|
80 | + { |
|
81 | + /** |
|
82 | + * Throw an exception if there's no event ID |
|
83 | + */ |
|
84 | + if (empty($args['eventId']) || ! absint($args['eventId'])) { |
|
85 | + throw new UserError(esc_html__( |
|
86 | + 'No event ID was provided to get the relational data for', |
|
87 | + 'event_espresso' |
|
88 | + )); |
|
89 | + } |
|
90 | 90 | |
91 | - $eventId = absint($args['eventId']); |
|
92 | - /** @var EventEntityRelations $event_entity_relations */ |
|
93 | - $event_entity_relations = LoaderFactory::getLoader()->getShared( |
|
94 | - 'EventEspresso\core\domain\services\admin\events\editor\EventEntityRelations' |
|
95 | - ); |
|
96 | - return json_encode($event_entity_relations->getData($eventId)); |
|
97 | - } |
|
91 | + $eventId = absint($args['eventId']); |
|
92 | + /** @var EventEntityRelations $event_entity_relations */ |
|
93 | + $event_entity_relations = LoaderFactory::getLoader()->getShared( |
|
94 | + 'EventEspresso\core\domain\services\admin\events\editor\EventEntityRelations' |
|
95 | + ); |
|
96 | + return json_encode($event_entity_relations->getData($eventId)); |
|
97 | + } |
|
98 | 98 | } |
@@ -16,97 +16,97 @@ |
||
16 | 16 | abstract class InputBase implements InputInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var string $namespace The graphql namespace/prefix. |
|
21 | - */ |
|
22 | - protected $namespace = 'Espresso'; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var string $name |
|
26 | - */ |
|
27 | - protected $name = ''; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var string $description |
|
31 | - */ |
|
32 | - protected $description = ''; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var GraphQLFieldInterface[] $fields |
|
36 | - */ |
|
37 | - protected $fields = []; |
|
38 | - |
|
39 | - /** |
|
40 | - * InputBase constructor. |
|
41 | - */ |
|
42 | - public function __construct() |
|
43 | - { |
|
44 | - $this->setFields($this->getFields()); |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @return GraphQLFieldInterface[] |
|
50 | - * @since $VID:$ |
|
51 | - */ |
|
52 | - abstract protected function getFields(); |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function name() |
|
59 | - { |
|
60 | - return $this->name; |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * @param string $name |
|
66 | - */ |
|
67 | - protected function setName($name) |
|
68 | - { |
|
69 | - $this->name = $name; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function description() |
|
77 | - { |
|
78 | - return $this->description; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @param string $description |
|
84 | - */ |
|
85 | - protected function setDescription($description) |
|
86 | - { |
|
87 | - $this->description = $description; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @return GraphQLFieldInterface[] |
|
93 | - * @since $VID:$ |
|
94 | - */ |
|
95 | - public function fields() |
|
96 | - { |
|
97 | - return (array) $this->fields; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @param GraphQLFieldInterface[] $fields |
|
103 | - */ |
|
104 | - protected function setFields(array $fields) |
|
105 | - { |
|
106 | - foreach ($fields as $field) { |
|
107 | - if ($field instanceof GraphQLField) { |
|
108 | - $this->fields[] = $field; |
|
109 | - } |
|
110 | - } |
|
111 | - } |
|
19 | + /** |
|
20 | + * @var string $namespace The graphql namespace/prefix. |
|
21 | + */ |
|
22 | + protected $namespace = 'Espresso'; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var string $name |
|
26 | + */ |
|
27 | + protected $name = ''; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var string $description |
|
31 | + */ |
|
32 | + protected $description = ''; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var GraphQLFieldInterface[] $fields |
|
36 | + */ |
|
37 | + protected $fields = []; |
|
38 | + |
|
39 | + /** |
|
40 | + * InputBase constructor. |
|
41 | + */ |
|
42 | + public function __construct() |
|
43 | + { |
|
44 | + $this->setFields($this->getFields()); |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @return GraphQLFieldInterface[] |
|
50 | + * @since $VID:$ |
|
51 | + */ |
|
52 | + abstract protected function getFields(); |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function name() |
|
59 | + { |
|
60 | + return $this->name; |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * @param string $name |
|
66 | + */ |
|
67 | + protected function setName($name) |
|
68 | + { |
|
69 | + $this->name = $name; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function description() |
|
77 | + { |
|
78 | + return $this->description; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @param string $description |
|
84 | + */ |
|
85 | + protected function setDescription($description) |
|
86 | + { |
|
87 | + $this->description = $description; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @return GraphQLFieldInterface[] |
|
93 | + * @since $VID:$ |
|
94 | + */ |
|
95 | + public function fields() |
|
96 | + { |
|
97 | + return (array) $this->fields; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @param GraphQLFieldInterface[] $fields |
|
103 | + */ |
|
104 | + protected function setFields(array $fields) |
|
105 | + { |
|
106 | + foreach ($fields as $field) { |
|
107 | + if ($field instanceof GraphQLField) { |
|
108 | + $this->fields[] = $field; |
|
109 | + } |
|
110 | + } |
|
111 | + } |
|
112 | 112 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | ), |
141 | 141 | ) |
142 | 142 | ); |
143 | - $this->_model_relations = array( |
|
143 | + $this->_model_relations = array( |
|
144 | 144 | 'Registration' => new EE_Has_Many_Relation(), |
145 | 145 | 'Payment' => new EE_Has_Many_Relation(), |
146 | 146 | 'Status' => new EE_Belongs_To_Relation(), |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | ), |
206 | 206 | OBJECT, |
207 | 207 | array( |
208 | - 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
208 | + 'txnDate' => array('DATE('.$query_interval.')', '%s'), |
|
209 | 209 | 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
210 | 210 | ) |
211 | 211 | ); |
@@ -225,17 +225,17 @@ discard block |
||
225 | 225 | public function get_revenue_per_event_report($period = '-1 month') |
226 | 226 | { |
227 | 227 | global $wpdb; |
228 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
229 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
230 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
228 | + $transaction_table = $wpdb->prefix.'esp_transaction'; |
|
229 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
230 | + $registration_payment_table = $wpdb->prefix.'esp_registration_payment'; |
|
231 | 231 | $event_table = $wpdb->posts; |
232 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
232 | + $payment_table = $wpdb->prefix.'esp_payment'; |
|
233 | 233 | $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
234 | 234 | $approved_payment_status = EEM_Payment::status_id_approved; |
235 | 235 | $extra_event_on_join = ''; |
236 | 236 | // exclude events not authored by user if permissions in effect |
237 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
238 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
237 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
238 | + $extra_event_on_join = ' AND Event.post_author = '.get_current_user_id(); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | return $wpdb->get_results( |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
310 | 310 | { |
311 | 311 | EE_Error::doing_it_wrong( |
312 | - __CLASS__ . '::' . __FUNCTION__, |
|
312 | + __CLASS__.'::'.__FUNCTION__, |
|
313 | 313 | sprintf( |
314 | 314 | __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
315 | 315 | 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | array( |
360 | 360 | 0 => array( |
361 | 361 | 'STS_ID' => EEM_Transaction::failed_status_code, |
362 | - 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
362 | + 'Payment.PAY_ID' => array('IS NULL'), |
|
363 | 363 | 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
364 | 364 | ), |
365 | 365 | 'order_by' => ['TXN_timestamp' => 'ASC'], |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | $time_to_leave_alone |
380 | 380 | ); |
381 | 381 | // now that we have the ids to delete |
382 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
382 | + if ( ! empty($txn_ids) && is_array($txn_ids)) { |
|
383 | 383 | // first, make sure these TXN's are removed the "ee_locked_transactions" array |
384 | 384 | EEM_Transaction::unset_locked_transactions($txn_ids); |
385 | 385 | |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | // let's get deletin'... |
393 | 393 | // We got the ids from the original query to get them FROM |
394 | 394 | // the db (which is sanitized) so no need to prepare them again. |
395 | - $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
395 | + $query = $wpdb->prepare("DELETE FROM ".$this->table()." WHERE TXN_ID IN ( $format )", $txn_ids); |
|
396 | 396 | $deleted = $wpdb->query($query); |
397 | 397 | } |
398 | 398 | if ($deleted) { |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | $locked_transactions = get_option('ee_locked_transactions', array()); |
417 | 417 | $update = false; |
418 | 418 | foreach ($transaction_IDs as $TXN_ID) { |
419 | - if (isset($locked_transactions[ $TXN_ID ])) { |
|
420 | - unset($locked_transactions[ $TXN_ID ]); |
|
419 | + if (isset($locked_transactions[$TXN_ID])) { |
|
420 | + unset($locked_transactions[$TXN_ID]); |
|
421 | 421 | $update = true; |
422 | 422 | } |
423 | 423 | } |
@@ -16,230 +16,230 @@ discard block |
||
16 | 16 | class EEM_Transaction extends EEM_Base |
17 | 17 | { |
18 | 18 | |
19 | - // private instance of the Transaction object |
|
20 | - protected static $_instance; |
|
21 | - |
|
22 | - /** |
|
23 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
24 | - * but payment is pending. This is the state for transactions where payment is promised |
|
25 | - * from an offline gateway. |
|
26 | - */ |
|
27 | - // const open_status_code = 'TPN'; |
|
28 | - |
|
29 | - /** |
|
30 | - * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
31 | - * either due to a technical reason (server or computer crash during registration), |
|
32 | - * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
33 | - */ |
|
34 | - const failed_status_code = 'TFL'; |
|
35 | - |
|
36 | - /** |
|
37 | - * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
38 | - * either due to a technical reason (server or computer crash during registration), |
|
39 | - * or due to an abandoned cart after registrant chose not to complete the registration process |
|
40 | - * HOWEVER... |
|
41 | - * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
42 | - * registrant |
|
43 | - */ |
|
44 | - const abandoned_status_code = 'TAB'; |
|
45 | - |
|
46 | - /** |
|
47 | - * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
48 | - * meaning that monies are still owing: TXN_paid < TXN_total |
|
49 | - */ |
|
50 | - const incomplete_status_code = 'TIN'; |
|
51 | - |
|
52 | - /** |
|
53 | - * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
54 | - * meaning that NO monies are owing: TXN_paid == TXN_total |
|
55 | - */ |
|
56 | - const complete_status_code = 'TCM'; |
|
57 | - |
|
58 | - /** |
|
59 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
60 | - * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
61 | - */ |
|
62 | - const overpaid_status_code = 'TOP'; |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * private constructor to prevent direct creation |
|
67 | - * |
|
68 | - * @Constructor |
|
69 | - * @access protected |
|
70 | - * |
|
71 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
72 | - * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
73 | - * date time model field objects. Default is NULL (and will be assumed using the set |
|
74 | - * timezone in the 'timezone_string' wp option) |
|
75 | - * |
|
76 | - * @return EEM_Transaction |
|
77 | - * @throws \EE_Error |
|
78 | - */ |
|
79 | - protected function __construct($timezone) |
|
80 | - { |
|
81 | - $this->singular_item = __('Transaction', 'event_espresso'); |
|
82 | - $this->plural_item = __('Transactions', 'event_espresso'); |
|
83 | - |
|
84 | - $this->_tables = array( |
|
85 | - 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') |
|
86 | - ); |
|
87 | - $this->_fields = array( |
|
88 | - 'TransactionTable' => array( |
|
89 | - 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
90 | - 'TXN_timestamp' => new EE_Datetime_Field( |
|
91 | - 'TXN_timestamp', |
|
92 | - __('date when transaction was created', 'event_espresso'), |
|
93 | - false, |
|
94 | - EE_Datetime_Field::now, |
|
95 | - $timezone |
|
96 | - ), |
|
97 | - 'TXN_total' => new EE_Money_Field( |
|
98 | - 'TXN_total', |
|
99 | - __('Total value of Transaction', 'event_espresso'), |
|
100 | - false, |
|
101 | - 0 |
|
102 | - ), |
|
103 | - 'TXN_paid' => new EE_Money_Field( |
|
104 | - 'TXN_paid', |
|
105 | - __('Amount paid towards transaction to date', 'event_espresso'), |
|
106 | - false, |
|
107 | - 0 |
|
108 | - ), |
|
109 | - 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
110 | - 'STS_ID', |
|
111 | - __('Status ID', 'event_espresso'), |
|
112 | - false, |
|
113 | - EEM_Transaction::failed_status_code, |
|
114 | - 'Status' |
|
115 | - ), |
|
116 | - 'TXN_session_data' => new EE_Serialized_Text_Field( |
|
117 | - 'TXN_session_data', |
|
118 | - __('Serialized session data', 'event_espresso'), |
|
119 | - true, |
|
120 | - '' |
|
121 | - ), |
|
122 | - 'TXN_hash_salt' => new EE_Plain_Text_Field( |
|
123 | - 'TXN_hash_salt', |
|
124 | - __('Transaction Hash Salt', 'event_espresso'), |
|
125 | - true, |
|
126 | - '' |
|
127 | - ), |
|
128 | - 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
129 | - 'PMD_ID', |
|
130 | - __("Last Used Payment Method", 'event_espresso'), |
|
131 | - true, |
|
132 | - null, |
|
133 | - 'Payment_Method' |
|
134 | - ), |
|
135 | - 'TXN_reg_steps' => new EE_Serialized_Text_Field( |
|
136 | - 'TXN_reg_steps', |
|
137 | - __('Registration Steps', 'event_espresso'), |
|
138 | - false, |
|
139 | - array() |
|
140 | - ), |
|
141 | - ) |
|
142 | - ); |
|
143 | - $this->_model_relations = array( |
|
144 | - 'Registration' => new EE_Has_Many_Relation(), |
|
145 | - 'Payment' => new EE_Has_Many_Relation(), |
|
146 | - 'Status' => new EE_Belongs_To_Relation(), |
|
147 | - 'Line_Item' => new EE_Has_Many_Relation(false), |
|
148 | - // you can delete a transaction without needing to delete its line items |
|
149 | - 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
150 | - 'Message' => new EE_Has_Many_Relation() |
|
151 | - ); |
|
152 | - $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
153 | - parent::__construct($timezone); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * txn_status_array |
|
159 | - * get list of transaction statuses |
|
160 | - * |
|
161 | - * @access public |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - public static function txn_status_array() |
|
165 | - { |
|
166 | - return apply_filters( |
|
167 | - 'FHEE__EEM_Transaction__txn_status_array', |
|
168 | - array( |
|
169 | - EEM_Transaction::overpaid_status_code, |
|
170 | - EEM_Transaction::complete_status_code, |
|
171 | - EEM_Transaction::incomplete_status_code, |
|
172 | - EEM_Transaction::abandoned_status_code, |
|
173 | - EEM_Transaction::failed_status_code, |
|
174 | - ) |
|
175 | - ); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * get the revenue per day for the Transaction Admin page Reports Tab |
|
180 | - * |
|
181 | - * @access public |
|
182 | - * |
|
183 | - * @param string $period |
|
184 | - * |
|
185 | - * @return \stdClass[] |
|
186 | - */ |
|
187 | - public function get_revenue_per_day_report($period = '-1 month') |
|
188 | - { |
|
189 | - $sql_date = $this->convert_datetime_for_query( |
|
190 | - 'TXN_timestamp', |
|
191 | - date('Y-m-d H:i:s', strtotime($period)), |
|
192 | - 'Y-m-d H:i:s', |
|
193 | - 'UTC' |
|
194 | - ); |
|
195 | - |
|
196 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
197 | - |
|
198 | - return $this->_get_all_wpdb_results( |
|
199 | - array( |
|
200 | - array( |
|
201 | - 'TXN_timestamp' => array('>=', $sql_date) |
|
202 | - ), |
|
203 | - 'group_by' => 'txnDate', |
|
204 | - 'order_by' => array('TXN_timestamp' => 'ASC') |
|
205 | - ), |
|
206 | - OBJECT, |
|
207 | - array( |
|
208 | - 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
209 | - 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
|
210 | - ) |
|
211 | - ); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * get the revenue per event for the Transaction Admin page Reports Tab |
|
217 | - * |
|
218 | - * @access public |
|
219 | - * |
|
220 | - * @param string $period |
|
221 | - * |
|
222 | - * @throws \EE_Error |
|
223 | - * @return mixed |
|
224 | - */ |
|
225 | - public function get_revenue_per_event_report($period = '-1 month') |
|
226 | - { |
|
227 | - global $wpdb; |
|
228 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
229 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
230 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
231 | - $event_table = $wpdb->posts; |
|
232 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
233 | - $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
234 | - $approved_payment_status = EEM_Payment::status_id_approved; |
|
235 | - $extra_event_on_join = ''; |
|
236 | - // exclude events not authored by user if permissions in effect |
|
237 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
238 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
239 | - } |
|
240 | - |
|
241 | - return $wpdb->get_results( |
|
242 | - "SELECT |
|
19 | + // private instance of the Transaction object |
|
20 | + protected static $_instance; |
|
21 | + |
|
22 | + /** |
|
23 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
24 | + * but payment is pending. This is the state for transactions where payment is promised |
|
25 | + * from an offline gateway. |
|
26 | + */ |
|
27 | + // const open_status_code = 'TPN'; |
|
28 | + |
|
29 | + /** |
|
30 | + * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
31 | + * either due to a technical reason (server or computer crash during registration), |
|
32 | + * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
33 | + */ |
|
34 | + const failed_status_code = 'TFL'; |
|
35 | + |
|
36 | + /** |
|
37 | + * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
38 | + * either due to a technical reason (server or computer crash during registration), |
|
39 | + * or due to an abandoned cart after registrant chose not to complete the registration process |
|
40 | + * HOWEVER... |
|
41 | + * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
42 | + * registrant |
|
43 | + */ |
|
44 | + const abandoned_status_code = 'TAB'; |
|
45 | + |
|
46 | + /** |
|
47 | + * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
48 | + * meaning that monies are still owing: TXN_paid < TXN_total |
|
49 | + */ |
|
50 | + const incomplete_status_code = 'TIN'; |
|
51 | + |
|
52 | + /** |
|
53 | + * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
54 | + * meaning that NO monies are owing: TXN_paid == TXN_total |
|
55 | + */ |
|
56 | + const complete_status_code = 'TCM'; |
|
57 | + |
|
58 | + /** |
|
59 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
60 | + * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
61 | + */ |
|
62 | + const overpaid_status_code = 'TOP'; |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * private constructor to prevent direct creation |
|
67 | + * |
|
68 | + * @Constructor |
|
69 | + * @access protected |
|
70 | + * |
|
71 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
72 | + * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
73 | + * date time model field objects. Default is NULL (and will be assumed using the set |
|
74 | + * timezone in the 'timezone_string' wp option) |
|
75 | + * |
|
76 | + * @return EEM_Transaction |
|
77 | + * @throws \EE_Error |
|
78 | + */ |
|
79 | + protected function __construct($timezone) |
|
80 | + { |
|
81 | + $this->singular_item = __('Transaction', 'event_espresso'); |
|
82 | + $this->plural_item = __('Transactions', 'event_espresso'); |
|
83 | + |
|
84 | + $this->_tables = array( |
|
85 | + 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') |
|
86 | + ); |
|
87 | + $this->_fields = array( |
|
88 | + 'TransactionTable' => array( |
|
89 | + 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
90 | + 'TXN_timestamp' => new EE_Datetime_Field( |
|
91 | + 'TXN_timestamp', |
|
92 | + __('date when transaction was created', 'event_espresso'), |
|
93 | + false, |
|
94 | + EE_Datetime_Field::now, |
|
95 | + $timezone |
|
96 | + ), |
|
97 | + 'TXN_total' => new EE_Money_Field( |
|
98 | + 'TXN_total', |
|
99 | + __('Total value of Transaction', 'event_espresso'), |
|
100 | + false, |
|
101 | + 0 |
|
102 | + ), |
|
103 | + 'TXN_paid' => new EE_Money_Field( |
|
104 | + 'TXN_paid', |
|
105 | + __('Amount paid towards transaction to date', 'event_espresso'), |
|
106 | + false, |
|
107 | + 0 |
|
108 | + ), |
|
109 | + 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
110 | + 'STS_ID', |
|
111 | + __('Status ID', 'event_espresso'), |
|
112 | + false, |
|
113 | + EEM_Transaction::failed_status_code, |
|
114 | + 'Status' |
|
115 | + ), |
|
116 | + 'TXN_session_data' => new EE_Serialized_Text_Field( |
|
117 | + 'TXN_session_data', |
|
118 | + __('Serialized session data', 'event_espresso'), |
|
119 | + true, |
|
120 | + '' |
|
121 | + ), |
|
122 | + 'TXN_hash_salt' => new EE_Plain_Text_Field( |
|
123 | + 'TXN_hash_salt', |
|
124 | + __('Transaction Hash Salt', 'event_espresso'), |
|
125 | + true, |
|
126 | + '' |
|
127 | + ), |
|
128 | + 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
129 | + 'PMD_ID', |
|
130 | + __("Last Used Payment Method", 'event_espresso'), |
|
131 | + true, |
|
132 | + null, |
|
133 | + 'Payment_Method' |
|
134 | + ), |
|
135 | + 'TXN_reg_steps' => new EE_Serialized_Text_Field( |
|
136 | + 'TXN_reg_steps', |
|
137 | + __('Registration Steps', 'event_espresso'), |
|
138 | + false, |
|
139 | + array() |
|
140 | + ), |
|
141 | + ) |
|
142 | + ); |
|
143 | + $this->_model_relations = array( |
|
144 | + 'Registration' => new EE_Has_Many_Relation(), |
|
145 | + 'Payment' => new EE_Has_Many_Relation(), |
|
146 | + 'Status' => new EE_Belongs_To_Relation(), |
|
147 | + 'Line_Item' => new EE_Has_Many_Relation(false), |
|
148 | + // you can delete a transaction without needing to delete its line items |
|
149 | + 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
150 | + 'Message' => new EE_Has_Many_Relation() |
|
151 | + ); |
|
152 | + $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
153 | + parent::__construct($timezone); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * txn_status_array |
|
159 | + * get list of transaction statuses |
|
160 | + * |
|
161 | + * @access public |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + public static function txn_status_array() |
|
165 | + { |
|
166 | + return apply_filters( |
|
167 | + 'FHEE__EEM_Transaction__txn_status_array', |
|
168 | + array( |
|
169 | + EEM_Transaction::overpaid_status_code, |
|
170 | + EEM_Transaction::complete_status_code, |
|
171 | + EEM_Transaction::incomplete_status_code, |
|
172 | + EEM_Transaction::abandoned_status_code, |
|
173 | + EEM_Transaction::failed_status_code, |
|
174 | + ) |
|
175 | + ); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * get the revenue per day for the Transaction Admin page Reports Tab |
|
180 | + * |
|
181 | + * @access public |
|
182 | + * |
|
183 | + * @param string $period |
|
184 | + * |
|
185 | + * @return \stdClass[] |
|
186 | + */ |
|
187 | + public function get_revenue_per_day_report($period = '-1 month') |
|
188 | + { |
|
189 | + $sql_date = $this->convert_datetime_for_query( |
|
190 | + 'TXN_timestamp', |
|
191 | + date('Y-m-d H:i:s', strtotime($period)), |
|
192 | + 'Y-m-d H:i:s', |
|
193 | + 'UTC' |
|
194 | + ); |
|
195 | + |
|
196 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
197 | + |
|
198 | + return $this->_get_all_wpdb_results( |
|
199 | + array( |
|
200 | + array( |
|
201 | + 'TXN_timestamp' => array('>=', $sql_date) |
|
202 | + ), |
|
203 | + 'group_by' => 'txnDate', |
|
204 | + 'order_by' => array('TXN_timestamp' => 'ASC') |
|
205 | + ), |
|
206 | + OBJECT, |
|
207 | + array( |
|
208 | + 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
209 | + 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
|
210 | + ) |
|
211 | + ); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * get the revenue per event for the Transaction Admin page Reports Tab |
|
217 | + * |
|
218 | + * @access public |
|
219 | + * |
|
220 | + * @param string $period |
|
221 | + * |
|
222 | + * @throws \EE_Error |
|
223 | + * @return mixed |
|
224 | + */ |
|
225 | + public function get_revenue_per_event_report($period = '-1 month') |
|
226 | + { |
|
227 | + global $wpdb; |
|
228 | + $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
229 | + $registration_table = $wpdb->prefix . 'esp_registration'; |
|
230 | + $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
231 | + $event_table = $wpdb->posts; |
|
232 | + $payment_table = $wpdb->prefix . 'esp_payment'; |
|
233 | + $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
234 | + $approved_payment_status = EEM_Payment::status_id_approved; |
|
235 | + $extra_event_on_join = ''; |
|
236 | + // exclude events not authored by user if permissions in effect |
|
237 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
238 | + $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
239 | + } |
|
240 | + |
|
241 | + return $wpdb->get_results( |
|
242 | + "SELECT |
|
243 | 243 | Transaction_Event.event_name AS event_name, |
244 | 244 | SUM(Transaction_Event.paid) AS revenue |
245 | 245 | FROM |
@@ -267,233 +267,233 @@ discard block |
||
267 | 267 | $extra_event_on_join |
268 | 268 | ) AS Transaction_Event |
269 | 269 | GROUP BY event_name", |
270 | - OBJECT |
|
271 | - ); |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
277 | - * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
278 | - * the registration pointed to by reg_url_link), if not returns null |
|
279 | - * |
|
280 | - * @param string $reg_url_link |
|
281 | - * |
|
282 | - * @return EE_Transaction |
|
283 | - */ |
|
284 | - public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
285 | - { |
|
286 | - return $this->get_one(array( |
|
287 | - array( |
|
288 | - 'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get( |
|
289 | - 'e_reg_url_link', |
|
290 | - '' |
|
291 | - ) |
|
292 | - ) |
|
293 | - )); |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * Updates the provided EE_Transaction with all the applicable payments |
|
299 | - * (or fetch the EE_Transaction from its ID) |
|
300 | - * |
|
301 | - * @deprecated |
|
302 | - * |
|
303 | - * @param EE_Transaction|int $transaction_obj_or_id |
|
304 | - * @param boolean $save_txn whether or not to save the transaction during this function call |
|
305 | - * |
|
306 | - * @return boolean |
|
307 | - * @throws \EE_Error |
|
308 | - */ |
|
309 | - public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
310 | - { |
|
311 | - EE_Error::doing_it_wrong( |
|
312 | - __CLASS__ . '::' . __FUNCTION__, |
|
313 | - sprintf( |
|
314 | - __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
315 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
316 | - ), |
|
317 | - '4.6.0' |
|
318 | - ); |
|
319 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
320 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
321 | - |
|
322 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
323 | - $this->ensure_is_obj($transaction_obj_or_id) |
|
324 | - ); |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
329 | - * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
330 | - * and so we only use wpdb directly and only do minimal joins. |
|
331 | - * Transactions are considered "junk" if they're failed for longer than a week. |
|
332 | - * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
333 | - * it, it's probably not junk (regardless of what status it has). |
|
334 | - * The downside to this approach is that is addons are listening for object deletions |
|
335 | - * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
336 | - * to catch these types of deletions. |
|
337 | - * |
|
338 | - * @global WPDB $wpdb |
|
339 | - * @return mixed |
|
340 | - */ |
|
341 | - public function delete_junk_transactions() |
|
342 | - { |
|
343 | - /** @type WPDB $wpdb */ |
|
344 | - global $wpdb; |
|
345 | - $deleted = false; |
|
346 | - $time_to_leave_alone = apply_filters( |
|
347 | - 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone', |
|
348 | - WEEK_IN_SECONDS |
|
349 | - ); |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
354 | - * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
355 | - * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
356 | - */ |
|
357 | - $ids_query = apply_filters( |
|
358 | - 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
359 | - array( |
|
360 | - 0 => array( |
|
361 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
362 | - 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
363 | - 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
|
364 | - ), |
|
365 | - 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
366 | - 'limit' => 1000 |
|
367 | - ), |
|
368 | - $time_to_leave_alone |
|
369 | - ); |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
374 | - * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
375 | - */ |
|
376 | - $txn_ids = apply_filters( |
|
377 | - 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
378 | - EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
379 | - $time_to_leave_alone |
|
380 | - ); |
|
381 | - // now that we have the ids to delete |
|
382 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
383 | - // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
384 | - EEM_Transaction::unset_locked_transactions($txn_ids); |
|
385 | - |
|
386 | - // Create IDs placeholder. |
|
387 | - $placeholders = array_fill(0, count($txn_ids), '%d'); |
|
388 | - |
|
389 | - // Glue it together to use inside $wpdb->prepare. |
|
390 | - $format = implode(', ', $placeholders); |
|
391 | - |
|
392 | - // let's get deletin'... |
|
393 | - // We got the ids from the original query to get them FROM |
|
394 | - // the db (which is sanitized) so no need to prepare them again. |
|
395 | - $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
396 | - $deleted = $wpdb->query($query); |
|
397 | - } |
|
398 | - if ($deleted) { |
|
399 | - /** |
|
400 | - * Allows code to do something after the transactions have been deleted. |
|
401 | - */ |
|
402 | - do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
403 | - } |
|
404 | - |
|
405 | - return $deleted; |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - /** |
|
410 | - * @param array $transaction_IDs |
|
411 | - * |
|
412 | - * @return bool |
|
413 | - */ |
|
414 | - public static function unset_locked_transactions(array $transaction_IDs) |
|
415 | - { |
|
416 | - $locked_transactions = get_option('ee_locked_transactions', array()); |
|
417 | - $update = false; |
|
418 | - foreach ($transaction_IDs as $TXN_ID) { |
|
419 | - if (isset($locked_transactions[ $TXN_ID ])) { |
|
420 | - unset($locked_transactions[ $TXN_ID ]); |
|
421 | - $update = true; |
|
422 | - } |
|
423 | - } |
|
424 | - if ($update) { |
|
425 | - update_option('ee_locked_transactions', $locked_transactions); |
|
426 | - } |
|
427 | - |
|
428 | - return $update; |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * returns an array of EE_Transaction objects whose timestamp is greater than |
|
435 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
436 | - * |
|
437 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
438 | - * @throws EE_Error |
|
439 | - * @throws InvalidArgumentException |
|
440 | - * @throws InvalidDataTypeException |
|
441 | - * @throws InvalidInterfaceException |
|
442 | - */ |
|
443 | - public function get_transactions_in_progress() |
|
444 | - { |
|
445 | - return $this->_get_transactions_in_progress(); |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * returns an array of EE_Transaction objects whose timestamp is less than |
|
452 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
453 | - * |
|
454 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
455 | - * @throws EE_Error |
|
456 | - * @throws InvalidArgumentException |
|
457 | - * @throws InvalidDataTypeException |
|
458 | - * @throws InvalidInterfaceException |
|
459 | - */ |
|
460 | - public function get_transactions_not_in_progress() |
|
461 | - { |
|
462 | - return $this->_get_transactions_in_progress('<='); |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * @param string $comparison |
|
469 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
470 | - * @throws EE_Error |
|
471 | - * @throws InvalidArgumentException |
|
472 | - * @throws InvalidDataTypeException |
|
473 | - * @throws InvalidInterfaceException |
|
474 | - */ |
|
475 | - private function _get_transactions_in_progress($comparison = '>=') |
|
476 | - { |
|
477 | - $comparison = $comparison === '>=' || $comparison === '<=' |
|
478 | - ? $comparison |
|
479 | - : '>='; |
|
480 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
481 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
482 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
483 | - ); |
|
484 | - return $this->get_all( |
|
485 | - array( |
|
486 | - array( |
|
487 | - 'TXN_timestamp' => array( |
|
488 | - $comparison, |
|
489 | - $session_lifespan->expiration() |
|
490 | - ), |
|
491 | - 'STS_ID' => array( |
|
492 | - '!=', |
|
493 | - EEM_Transaction::complete_status_code |
|
494 | - ), |
|
495 | - ) |
|
496 | - ) |
|
497 | - ); |
|
498 | - } |
|
270 | + OBJECT |
|
271 | + ); |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
277 | + * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
278 | + * the registration pointed to by reg_url_link), if not returns null |
|
279 | + * |
|
280 | + * @param string $reg_url_link |
|
281 | + * |
|
282 | + * @return EE_Transaction |
|
283 | + */ |
|
284 | + public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
285 | + { |
|
286 | + return $this->get_one(array( |
|
287 | + array( |
|
288 | + 'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get( |
|
289 | + 'e_reg_url_link', |
|
290 | + '' |
|
291 | + ) |
|
292 | + ) |
|
293 | + )); |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * Updates the provided EE_Transaction with all the applicable payments |
|
299 | + * (or fetch the EE_Transaction from its ID) |
|
300 | + * |
|
301 | + * @deprecated |
|
302 | + * |
|
303 | + * @param EE_Transaction|int $transaction_obj_or_id |
|
304 | + * @param boolean $save_txn whether or not to save the transaction during this function call |
|
305 | + * |
|
306 | + * @return boolean |
|
307 | + * @throws \EE_Error |
|
308 | + */ |
|
309 | + public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
310 | + { |
|
311 | + EE_Error::doing_it_wrong( |
|
312 | + __CLASS__ . '::' . __FUNCTION__, |
|
313 | + sprintf( |
|
314 | + __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
315 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
316 | + ), |
|
317 | + '4.6.0' |
|
318 | + ); |
|
319 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
320 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
321 | + |
|
322 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
323 | + $this->ensure_is_obj($transaction_obj_or_id) |
|
324 | + ); |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
329 | + * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
330 | + * and so we only use wpdb directly and only do minimal joins. |
|
331 | + * Transactions are considered "junk" if they're failed for longer than a week. |
|
332 | + * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
333 | + * it, it's probably not junk (regardless of what status it has). |
|
334 | + * The downside to this approach is that is addons are listening for object deletions |
|
335 | + * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
336 | + * to catch these types of deletions. |
|
337 | + * |
|
338 | + * @global WPDB $wpdb |
|
339 | + * @return mixed |
|
340 | + */ |
|
341 | + public function delete_junk_transactions() |
|
342 | + { |
|
343 | + /** @type WPDB $wpdb */ |
|
344 | + global $wpdb; |
|
345 | + $deleted = false; |
|
346 | + $time_to_leave_alone = apply_filters( |
|
347 | + 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone', |
|
348 | + WEEK_IN_SECONDS |
|
349 | + ); |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
354 | + * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
355 | + * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
356 | + */ |
|
357 | + $ids_query = apply_filters( |
|
358 | + 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
359 | + array( |
|
360 | + 0 => array( |
|
361 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
362 | + 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
363 | + 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
|
364 | + ), |
|
365 | + 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
366 | + 'limit' => 1000 |
|
367 | + ), |
|
368 | + $time_to_leave_alone |
|
369 | + ); |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
374 | + * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
375 | + */ |
|
376 | + $txn_ids = apply_filters( |
|
377 | + 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
378 | + EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
379 | + $time_to_leave_alone |
|
380 | + ); |
|
381 | + // now that we have the ids to delete |
|
382 | + if (! empty($txn_ids) && is_array($txn_ids)) { |
|
383 | + // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
384 | + EEM_Transaction::unset_locked_transactions($txn_ids); |
|
385 | + |
|
386 | + // Create IDs placeholder. |
|
387 | + $placeholders = array_fill(0, count($txn_ids), '%d'); |
|
388 | + |
|
389 | + // Glue it together to use inside $wpdb->prepare. |
|
390 | + $format = implode(', ', $placeholders); |
|
391 | + |
|
392 | + // let's get deletin'... |
|
393 | + // We got the ids from the original query to get them FROM |
|
394 | + // the db (which is sanitized) so no need to prepare them again. |
|
395 | + $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
396 | + $deleted = $wpdb->query($query); |
|
397 | + } |
|
398 | + if ($deleted) { |
|
399 | + /** |
|
400 | + * Allows code to do something after the transactions have been deleted. |
|
401 | + */ |
|
402 | + do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
403 | + } |
|
404 | + |
|
405 | + return $deleted; |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + /** |
|
410 | + * @param array $transaction_IDs |
|
411 | + * |
|
412 | + * @return bool |
|
413 | + */ |
|
414 | + public static function unset_locked_transactions(array $transaction_IDs) |
|
415 | + { |
|
416 | + $locked_transactions = get_option('ee_locked_transactions', array()); |
|
417 | + $update = false; |
|
418 | + foreach ($transaction_IDs as $TXN_ID) { |
|
419 | + if (isset($locked_transactions[ $TXN_ID ])) { |
|
420 | + unset($locked_transactions[ $TXN_ID ]); |
|
421 | + $update = true; |
|
422 | + } |
|
423 | + } |
|
424 | + if ($update) { |
|
425 | + update_option('ee_locked_transactions', $locked_transactions); |
|
426 | + } |
|
427 | + |
|
428 | + return $update; |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * returns an array of EE_Transaction objects whose timestamp is greater than |
|
435 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
436 | + * |
|
437 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
438 | + * @throws EE_Error |
|
439 | + * @throws InvalidArgumentException |
|
440 | + * @throws InvalidDataTypeException |
|
441 | + * @throws InvalidInterfaceException |
|
442 | + */ |
|
443 | + public function get_transactions_in_progress() |
|
444 | + { |
|
445 | + return $this->_get_transactions_in_progress(); |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * returns an array of EE_Transaction objects whose timestamp is less than |
|
452 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
453 | + * |
|
454 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
455 | + * @throws EE_Error |
|
456 | + * @throws InvalidArgumentException |
|
457 | + * @throws InvalidDataTypeException |
|
458 | + * @throws InvalidInterfaceException |
|
459 | + */ |
|
460 | + public function get_transactions_not_in_progress() |
|
461 | + { |
|
462 | + return $this->_get_transactions_in_progress('<='); |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * @param string $comparison |
|
469 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
470 | + * @throws EE_Error |
|
471 | + * @throws InvalidArgumentException |
|
472 | + * @throws InvalidDataTypeException |
|
473 | + * @throws InvalidInterfaceException |
|
474 | + */ |
|
475 | + private function _get_transactions_in_progress($comparison = '>=') |
|
476 | + { |
|
477 | + $comparison = $comparison === '>=' || $comparison === '<=' |
|
478 | + ? $comparison |
|
479 | + : '>='; |
|
480 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
481 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
482 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
483 | + ); |
|
484 | + return $this->get_all( |
|
485 | + array( |
|
486 | + array( |
|
487 | + 'TXN_timestamp' => array( |
|
488 | + $comparison, |
|
489 | + $session_lifespan->expiration() |
|
490 | + ), |
|
491 | + 'STS_ID' => array( |
|
492 | + '!=', |
|
493 | + EEM_Transaction::complete_status_code |
|
494 | + ), |
|
495 | + ) |
|
496 | + ) |
|
497 | + ); |
|
498 | + } |
|
499 | 499 | } |
@@ -32,158 +32,158 @@ |
||
32 | 32 | */ |
33 | 33 | class ExecuteBatchDeletion extends JobHandler |
34 | 34 | { |
35 | - /** |
|
36 | - * @var NodeGroupDao |
|
37 | - */ |
|
38 | - protected $model_obj_node_group_persister; |
|
39 | - public function __construct(NodeGroupDao $model_obj_node_group_persister) |
|
40 | - { |
|
41 | - $this->model_obj_node_group_persister = $model_obj_node_group_persister; |
|
42 | - } |
|
35 | + /** |
|
36 | + * @var NodeGroupDao |
|
37 | + */ |
|
38 | + protected $model_obj_node_group_persister; |
|
39 | + public function __construct(NodeGroupDao $model_obj_node_group_persister) |
|
40 | + { |
|
41 | + $this->model_obj_node_group_persister = $model_obj_node_group_persister; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
46 | - /** |
|
47 | - * |
|
48 | - * @param JobParameters $job_parameters |
|
49 | - * @throws BatchRequestException |
|
50 | - * @return JobStepResponse |
|
51 | - */ |
|
52 | - public function create_job(JobParameters $job_parameters) |
|
53 | - { |
|
54 | - $deletion_job_code = $job_parameters->request_datum('deletion_job_code', null); |
|
55 | - $roots = $this->model_obj_node_group_persister->getModelObjNodesInGroup($deletion_job_code); |
|
56 | - if ($roots === null) { |
|
57 | - throw new UnexpectedEntityException($roots, 'array', esc_html__('The job seems to be stale. Please press the back button in your browser twice.', 'event_espresso')); |
|
58 | - } |
|
59 | - $models_and_ids_to_delete = []; |
|
60 | - foreach ($roots as $root) { |
|
61 | - if (! $root instanceof ModelObjNode) { |
|
62 | - throw new UnexpectedEntityException($root, 'ModelObjNode'); |
|
63 | - } |
|
64 | - $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds()); |
|
65 | - } |
|
66 | - $job_parameters->set_extra_data( |
|
67 | - [ |
|
68 | - 'models_and_ids_to_delete' => $models_and_ids_to_delete |
|
69 | - ] |
|
70 | - ); |
|
71 | - // Find the job's actual size. |
|
72 | - $job_size = 0; |
|
73 | - foreach ($models_and_ids_to_delete as $model_name => $ids) { |
|
74 | - $job_size += count($ids); |
|
75 | - } |
|
76 | - $job_parameters->set_job_size($job_size); |
|
77 | - return new JobStepResponse( |
|
78 | - $job_parameters, |
|
79 | - esc_html__('Beginning to delete items...', 'event_espresso') |
|
80 | - ); |
|
81 | - } |
|
45 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
46 | + /** |
|
47 | + * |
|
48 | + * @param JobParameters $job_parameters |
|
49 | + * @throws BatchRequestException |
|
50 | + * @return JobStepResponse |
|
51 | + */ |
|
52 | + public function create_job(JobParameters $job_parameters) |
|
53 | + { |
|
54 | + $deletion_job_code = $job_parameters->request_datum('deletion_job_code', null); |
|
55 | + $roots = $this->model_obj_node_group_persister->getModelObjNodesInGroup($deletion_job_code); |
|
56 | + if ($roots === null) { |
|
57 | + throw new UnexpectedEntityException($roots, 'array', esc_html__('The job seems to be stale. Please press the back button in your browser twice.', 'event_espresso')); |
|
58 | + } |
|
59 | + $models_and_ids_to_delete = []; |
|
60 | + foreach ($roots as $root) { |
|
61 | + if (! $root instanceof ModelObjNode) { |
|
62 | + throw new UnexpectedEntityException($root, 'ModelObjNode'); |
|
63 | + } |
|
64 | + $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds()); |
|
65 | + } |
|
66 | + $job_parameters->set_extra_data( |
|
67 | + [ |
|
68 | + 'models_and_ids_to_delete' => $models_and_ids_to_delete |
|
69 | + ] |
|
70 | + ); |
|
71 | + // Find the job's actual size. |
|
72 | + $job_size = 0; |
|
73 | + foreach ($models_and_ids_to_delete as $model_name => $ids) { |
|
74 | + $job_size += count($ids); |
|
75 | + } |
|
76 | + $job_parameters->set_job_size($job_size); |
|
77 | + return new JobStepResponse( |
|
78 | + $job_parameters, |
|
79 | + esc_html__('Beginning to delete items...', 'event_espresso') |
|
80 | + ); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Performs another step of the job |
|
85 | - * @param JobParameters $job_parameters |
|
86 | - * @param int $batch_size |
|
87 | - * @return JobStepResponse |
|
88 | - * @throws BatchRequestException |
|
89 | - */ |
|
90 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
91 | - { |
|
92 | - // We already have the items IDs. So deleting is really fast. Let's speed it up. |
|
93 | - $batch_size *= 10; |
|
94 | - $units_processed = 0; |
|
95 | - $models_and_ids_to_delete = $job_parameters->extra_datum('models_and_ids_to_delete', []); |
|
96 | - // Build a new list of everything leftover after this request's of deletions. |
|
97 | - $models_and_ids_remaining = []; |
|
98 | - foreach ($models_and_ids_to_delete as $model_name => $ids_to_delete) { |
|
99 | - if ($units_processed < $batch_size) { |
|
100 | - $model = EE_Registry::instance()->load_model($model_name); |
|
101 | - $ids_to_delete_this_query = array_slice($ids_to_delete, 0, $batch_size - $units_processed, true); |
|
102 | - if ($model->has_primary_key_field()) { |
|
103 | - $where_conditions = [ |
|
104 | - $model->primary_key_name() => [ |
|
105 | - 'IN', |
|
106 | - $ids_to_delete_this_query |
|
107 | - ] |
|
108 | - ]; |
|
109 | - } else { |
|
110 | - $where_conditions = [ |
|
111 | - 'OR' => [] |
|
112 | - ]; |
|
113 | - foreach ($ids_to_delete_this_query as $index_primary_key_string) { |
|
114 | - $keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string); |
|
115 | - $where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values; |
|
116 | - } |
|
117 | - } |
|
118 | - // Deleting time! |
|
119 | - // The model's deletion method reports every ROW deleted, and in the case of CPT models that will be |
|
120 | - // two rows deleted for event CPT item. So don't rely on it for the count of items deleted. |
|
121 | - $model->delete_permanently( |
|
122 | - [ |
|
123 | - $where_conditions |
|
124 | - ], |
|
125 | - false |
|
126 | - ); |
|
127 | - $units_processed += count($ids_to_delete_this_query); |
|
128 | - $remaining_ids = array_diff_key($ids_to_delete, $ids_to_delete_this_query); |
|
129 | - // If there's any more from this model, we'll do them next time. |
|
130 | - if (count($remaining_ids) > 0) { |
|
131 | - $models_and_ids_remaining[ $model_name ] = $remaining_ids; |
|
132 | - } |
|
133 | - } else { |
|
134 | - $models_and_ids_remaining[ $model_name ] = $models_and_ids_to_delete[ $model_name ]; |
|
135 | - } |
|
136 | - } |
|
137 | - $job_parameters->mark_processed($units_processed); |
|
138 | - // All done deleting for this request. Is there anything to do next time? |
|
139 | - if (empty($models_and_ids_remaining)) { |
|
140 | - $job_parameters->set_status(JobParameters::status_complete); |
|
141 | - return new JobStepResponse( |
|
142 | - $job_parameters, |
|
143 | - esc_html__('Deletion complete.', 'event_espresso') |
|
144 | - ); |
|
145 | - } |
|
146 | - $job_parameters->add_extra_data('models_and_ids_to_delete', $models_and_ids_remaining); |
|
147 | - return new JobStepResponse( |
|
148 | - $job_parameters, |
|
149 | - sprintf( |
|
150 | - esc_html__('Deleted %d items.', 'event_espresso'), |
|
151 | - $units_processed |
|
152 | - ) |
|
153 | - ); |
|
154 | - } |
|
83 | + /** |
|
84 | + * Performs another step of the job |
|
85 | + * @param JobParameters $job_parameters |
|
86 | + * @param int $batch_size |
|
87 | + * @return JobStepResponse |
|
88 | + * @throws BatchRequestException |
|
89 | + */ |
|
90 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
91 | + { |
|
92 | + // We already have the items IDs. So deleting is really fast. Let's speed it up. |
|
93 | + $batch_size *= 10; |
|
94 | + $units_processed = 0; |
|
95 | + $models_and_ids_to_delete = $job_parameters->extra_datum('models_and_ids_to_delete', []); |
|
96 | + // Build a new list of everything leftover after this request's of deletions. |
|
97 | + $models_and_ids_remaining = []; |
|
98 | + foreach ($models_and_ids_to_delete as $model_name => $ids_to_delete) { |
|
99 | + if ($units_processed < $batch_size) { |
|
100 | + $model = EE_Registry::instance()->load_model($model_name); |
|
101 | + $ids_to_delete_this_query = array_slice($ids_to_delete, 0, $batch_size - $units_processed, true); |
|
102 | + if ($model->has_primary_key_field()) { |
|
103 | + $where_conditions = [ |
|
104 | + $model->primary_key_name() => [ |
|
105 | + 'IN', |
|
106 | + $ids_to_delete_this_query |
|
107 | + ] |
|
108 | + ]; |
|
109 | + } else { |
|
110 | + $where_conditions = [ |
|
111 | + 'OR' => [] |
|
112 | + ]; |
|
113 | + foreach ($ids_to_delete_this_query as $index_primary_key_string) { |
|
114 | + $keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string); |
|
115 | + $where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values; |
|
116 | + } |
|
117 | + } |
|
118 | + // Deleting time! |
|
119 | + // The model's deletion method reports every ROW deleted, and in the case of CPT models that will be |
|
120 | + // two rows deleted for event CPT item. So don't rely on it for the count of items deleted. |
|
121 | + $model->delete_permanently( |
|
122 | + [ |
|
123 | + $where_conditions |
|
124 | + ], |
|
125 | + false |
|
126 | + ); |
|
127 | + $units_processed += count($ids_to_delete_this_query); |
|
128 | + $remaining_ids = array_diff_key($ids_to_delete, $ids_to_delete_this_query); |
|
129 | + // If there's any more from this model, we'll do them next time. |
|
130 | + if (count($remaining_ids) > 0) { |
|
131 | + $models_and_ids_remaining[ $model_name ] = $remaining_ids; |
|
132 | + } |
|
133 | + } else { |
|
134 | + $models_and_ids_remaining[ $model_name ] = $models_and_ids_to_delete[ $model_name ]; |
|
135 | + } |
|
136 | + } |
|
137 | + $job_parameters->mark_processed($units_processed); |
|
138 | + // All done deleting for this request. Is there anything to do next time? |
|
139 | + if (empty($models_and_ids_remaining)) { |
|
140 | + $job_parameters->set_status(JobParameters::status_complete); |
|
141 | + return new JobStepResponse( |
|
142 | + $job_parameters, |
|
143 | + esc_html__('Deletion complete.', 'event_espresso') |
|
144 | + ); |
|
145 | + } |
|
146 | + $job_parameters->add_extra_data('models_and_ids_to_delete', $models_and_ids_remaining); |
|
147 | + return new JobStepResponse( |
|
148 | + $job_parameters, |
|
149 | + sprintf( |
|
150 | + esc_html__('Deleted %d items.', 'event_espresso'), |
|
151 | + $units_processed |
|
152 | + ) |
|
153 | + ); |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * Performs any clean-up logic when we know the job is completed |
|
158 | - * @param JobParameters $job_parameters |
|
159 | - * @return JobStepResponse |
|
160 | - */ |
|
161 | - public function cleanup_job(JobParameters $job_parameters) |
|
162 | - { |
|
163 | - $this->model_obj_node_group_persister->deleteModelObjNodesInGroup( |
|
164 | - $job_parameters->request_datum('deletion_job_code') |
|
165 | - ); |
|
166 | - // For backwards compatibility with how we used to delete events, make sure we still trigger the old action. |
|
167 | - $models_and_ids_to_delete = $job_parameters->extra_datum('models_and_ids_to_delete', []); |
|
168 | - foreach ($models_and_ids_to_delete['Event'] as $event_id) { |
|
169 | - // Create a log entry so we know who and when this event was permanently deleted. |
|
170 | - (EE_Change_Log::new_instance( |
|
171 | - [ |
|
172 | - 'OBJ_ID' => $event_id, |
|
173 | - 'OBJ_type' => 'Event', |
|
174 | - 'LOG_message' => sprintf( |
|
175 | - esc_html__('Event %1$d permanently deleted using ExecuteBatchDeletion.', 'event_espresso'), |
|
176 | - $event_id |
|
177 | - ) |
|
178 | - ] |
|
179 | - ))->save(); |
|
180 | - do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $event_id); |
|
181 | - } |
|
182 | - return new JobStepResponse( |
|
183 | - $job_parameters, |
|
184 | - esc_html__('All done', 'event_espresso') |
|
185 | - ); |
|
186 | - } |
|
156 | + /** |
|
157 | + * Performs any clean-up logic when we know the job is completed |
|
158 | + * @param JobParameters $job_parameters |
|
159 | + * @return JobStepResponse |
|
160 | + */ |
|
161 | + public function cleanup_job(JobParameters $job_parameters) |
|
162 | + { |
|
163 | + $this->model_obj_node_group_persister->deleteModelObjNodesInGroup( |
|
164 | + $job_parameters->request_datum('deletion_job_code') |
|
165 | + ); |
|
166 | + // For backwards compatibility with how we used to delete events, make sure we still trigger the old action. |
|
167 | + $models_and_ids_to_delete = $job_parameters->extra_datum('models_and_ids_to_delete', []); |
|
168 | + foreach ($models_and_ids_to_delete['Event'] as $event_id) { |
|
169 | + // Create a log entry so we know who and when this event was permanently deleted. |
|
170 | + (EE_Change_Log::new_instance( |
|
171 | + [ |
|
172 | + 'OBJ_ID' => $event_id, |
|
173 | + 'OBJ_type' => 'Event', |
|
174 | + 'LOG_message' => sprintf( |
|
175 | + esc_html__('Event %1$d permanently deleted using ExecuteBatchDeletion.', 'event_espresso'), |
|
176 | + $event_id |
|
177 | + ) |
|
178 | + ] |
|
179 | + ))->save(); |
|
180 | + do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $event_id); |
|
181 | + } |
|
182 | + return new JobStepResponse( |
|
183 | + $job_parameters, |
|
184 | + esc_html__('All done', 'event_espresso') |
|
185 | + ); |
|
186 | + } |
|
187 | 187 | } |
188 | 188 | // End of file EventDeletion.php |
189 | 189 | // Location: EventEspressoBatchRequest\JobHandlers/EventDeletion.php |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | } |
59 | 59 | $models_and_ids_to_delete = []; |
60 | 60 | foreach ($roots as $root) { |
61 | - if (! $root instanceof ModelObjNode) { |
|
61 | + if ( ! $root instanceof ModelObjNode) { |
|
62 | 62 | throw new UnexpectedEntityException($root, 'ModelObjNode'); |
63 | 63 | } |
64 | 64 | $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds()); |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | ]; |
113 | 113 | foreach ($ids_to_delete_this_query as $index_primary_key_string) { |
114 | 114 | $keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string); |
115 | - $where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values; |
|
115 | + $where_conditions['OR']['AND*'.$index_primary_key_string] = $keys_n_values; |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | // Deleting time! |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | $remaining_ids = array_diff_key($ids_to_delete, $ids_to_delete_this_query); |
129 | 129 | // If there's any more from this model, we'll do them next time. |
130 | 130 | if (count($remaining_ids) > 0) { |
131 | - $models_and_ids_remaining[ $model_name ] = $remaining_ids; |
|
131 | + $models_and_ids_remaining[$model_name] = $remaining_ids; |
|
132 | 132 | } |
133 | 133 | } else { |
134 | - $models_and_ids_remaining[ $model_name ] = $models_and_ids_to_delete[ $model_name ]; |
|
134 | + $models_and_ids_remaining[$model_name] = $models_and_ids_to_delete[$model_name]; |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | $job_parameters->mark_processed($units_processed); |
@@ -89,17 +89,17 @@ discard block |
||
89 | 89 | $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : ''; |
90 | 90 | $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code); |
91 | 91 | $event_ids = isset($models_and_ids_to_delete['Event']) ? $models_and_ids_to_delete['Event'] : array(); |
92 | - if (empty($event_ids) || !is_array($event_ids)) { |
|
92 | + if (empty($event_ids) || ! is_array($event_ids)) { |
|
93 | 93 | throw new EE_Error( |
94 | 94 | esc_html__('No Events were found to delete.', 'event_espresso') |
95 | 95 | ); |
96 | 96 | } |
97 | 97 | $datetime_ids = isset($models_and_ids_to_delete['Datetime']) ? $models_and_ids_to_delete['Datetime'] : array(); |
98 | - if (!is_array($datetime_ids)) { |
|
98 | + if ( ! is_array($datetime_ids)) { |
|
99 | 99 | throw new UnexpectedEntityException($datetime_ids, 'array'); |
100 | 100 | } |
101 | 101 | $registration_ids = isset($models_and_ids_to_delete['Registration']) ? $models_and_ids_to_delete['Registration'] : array(); |
102 | - if (!is_array($registration_ids)) { |
|
102 | + if ( ! is_array($registration_ids)) { |
|
103 | 103 | throw new UnexpectedEntityException($registration_ids, 'array'); |
104 | 104 | } |
105 | 105 | $num_registrations_to_show = 10; |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | ]; |
136 | 136 | return [ |
137 | 137 | 'admin_page_content' => EEH_Template::display_template( |
138 | - EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php', |
|
138 | + EVENTS_TEMPLATE_PATH.'event_preview_deletion.template.php', |
|
139 | 139 | [ |
140 | 140 | 'form_url' => EE_Admin_Page::add_query_args_and_nonce( |
141 | 141 | $confirm_deletion_args, |
@@ -31,127 +31,127 @@ |
||
31 | 31 | */ |
32 | 32 | class PreviewDeletion |
33 | 33 | { |
34 | - /** |
|
35 | - * @var NodeGroupDao |
|
36 | - */ |
|
37 | - protected $dao; |
|
34 | + /** |
|
35 | + * @var NodeGroupDao |
|
36 | + */ |
|
37 | + protected $dao; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var EEM_Event |
|
41 | - */ |
|
42 | - protected $event_model; |
|
39 | + /** |
|
40 | + * @var EEM_Event |
|
41 | + */ |
|
42 | + protected $event_model; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @var EEM_Datetime |
|
46 | - */ |
|
47 | - protected $datetime_model; |
|
44 | + /** |
|
45 | + * @var EEM_Datetime |
|
46 | + */ |
|
47 | + protected $datetime_model; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @var EEM_Registration |
|
51 | - */ |
|
52 | - protected $registration_model; |
|
49 | + /** |
|
50 | + * @var EEM_Registration |
|
51 | + */ |
|
52 | + protected $registration_model; |
|
53 | 53 | |
54 | - /** |
|
55 | - * PreviewDeletion constructor. |
|
56 | - * @param NodeGroupDao $dao |
|
57 | - * @param EEM_Event $event_model |
|
58 | - * @param EEM_Datetime $datetime_model |
|
59 | - * @param EEM_Registration $registration_model |
|
60 | - */ |
|
61 | - public function __construct( |
|
62 | - NodeGroupDao $dao, |
|
63 | - EEM_Event $event_model, |
|
64 | - EEM_Datetime $datetime_model, |
|
65 | - EEM_Registration $registration_model |
|
66 | - ) { |
|
67 | - $this->dao = $dao; |
|
68 | - $this->event_model = $event_model; |
|
69 | - $this->datetime_model = $datetime_model; |
|
70 | - $this->registration_model = $registration_model; |
|
71 | - } |
|
54 | + /** |
|
55 | + * PreviewDeletion constructor. |
|
56 | + * @param NodeGroupDao $dao |
|
57 | + * @param EEM_Event $event_model |
|
58 | + * @param EEM_Datetime $datetime_model |
|
59 | + * @param EEM_Registration $registration_model |
|
60 | + */ |
|
61 | + public function __construct( |
|
62 | + NodeGroupDao $dao, |
|
63 | + EEM_Event $event_model, |
|
64 | + EEM_Datetime $datetime_model, |
|
65 | + EEM_Registration $registration_model |
|
66 | + ) { |
|
67 | + $this->dao = $dao; |
|
68 | + $this->event_model = $event_model; |
|
69 | + $this->datetime_model = $datetime_model; |
|
70 | + $this->registration_model = $registration_model; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Renders the preview deletion page. |
|
75 | - * @since 4.10.12.p |
|
76 | - * @param $request_data |
|
77 | - * @param $admin_base_url |
|
78 | - * @return array |
|
79 | - * @throws UnexpectedEntityException |
|
80 | - * @throws DomainException |
|
81 | - * @throws EE_Error |
|
82 | - * @throws InvalidDataTypeException |
|
83 | - * @throws InvalidInterfaceException |
|
84 | - * @throws InvalidArgumentException |
|
85 | - * @throws ReflectionException |
|
86 | - */ |
|
87 | - public function handle($request_data, $admin_base_url) |
|
88 | - { |
|
89 | - $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : ''; |
|
90 | - $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code); |
|
91 | - $event_ids = isset($models_and_ids_to_delete['Event']) ? $models_and_ids_to_delete['Event'] : array(); |
|
92 | - if (empty($event_ids) || !is_array($event_ids)) { |
|
93 | - throw new EE_Error( |
|
94 | - esc_html__('No Events were found to delete.', 'event_espresso') |
|
95 | - ); |
|
96 | - } |
|
97 | - $datetime_ids = isset($models_and_ids_to_delete['Datetime']) ? $models_and_ids_to_delete['Datetime'] : array(); |
|
98 | - if (!is_array($datetime_ids)) { |
|
99 | - throw new UnexpectedEntityException($datetime_ids, 'array'); |
|
100 | - } |
|
101 | - $registration_ids = isset($models_and_ids_to_delete['Registration']) ? $models_and_ids_to_delete['Registration'] : array(); |
|
102 | - if (!is_array($registration_ids)) { |
|
103 | - throw new UnexpectedEntityException($registration_ids, 'array'); |
|
104 | - } |
|
105 | - $num_registrations_to_show = 10; |
|
106 | - $reg_count = count($registration_ids); |
|
107 | - if ($reg_count > $num_registrations_to_show) { |
|
108 | - $registration_ids = array_slice($registration_ids, 0, $num_registrations_to_show); |
|
109 | - } |
|
110 | - $form = new ConfirmEventDeletionForm($event_ids); |
|
111 | - $events = $this->event_model->get_all_deleted_and_undeleted( |
|
112 | - [ |
|
113 | - [ |
|
114 | - 'EVT_ID' => ['IN', $event_ids] |
|
115 | - ] |
|
116 | - ] |
|
117 | - ); |
|
118 | - $datetimes = $this->datetime_model->get_all_deleted_and_undeleted( |
|
119 | - [ |
|
120 | - [ |
|
121 | - 'DTT_ID' => ['IN', $datetime_ids] |
|
122 | - ] |
|
123 | - ] |
|
124 | - ); |
|
125 | - $registrations = $this->registration_model->get_all_deleted_and_undeleted( |
|
126 | - [ |
|
127 | - [ |
|
128 | - 'REG_ID' => ['IN', $registration_ids] |
|
129 | - ] |
|
130 | - ] |
|
131 | - ); |
|
132 | - $confirm_deletion_args = [ |
|
133 | - 'action' => 'confirm_deletion', |
|
134 | - 'deletion_job_code' => $deletion_job_code |
|
135 | - ]; |
|
136 | - return [ |
|
137 | - 'admin_page_content' => EEH_Template::display_template( |
|
138 | - EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php', |
|
139 | - [ |
|
140 | - 'form_url' => EE_Admin_Page::add_query_args_and_nonce( |
|
141 | - $confirm_deletion_args, |
|
142 | - $admin_base_url |
|
143 | - ), |
|
144 | - 'form' => $form, |
|
145 | - 'events' => $events, |
|
146 | - 'datetimes' => $datetimes, |
|
147 | - 'registrations' => $registrations, |
|
148 | - 'reg_count' => $reg_count, |
|
149 | - 'num_registrations_to_show' => $num_registrations_to_show |
|
150 | - ], |
|
151 | - true |
|
152 | - ) |
|
153 | - ]; |
|
154 | - } |
|
73 | + /** |
|
74 | + * Renders the preview deletion page. |
|
75 | + * @since 4.10.12.p |
|
76 | + * @param $request_data |
|
77 | + * @param $admin_base_url |
|
78 | + * @return array |
|
79 | + * @throws UnexpectedEntityException |
|
80 | + * @throws DomainException |
|
81 | + * @throws EE_Error |
|
82 | + * @throws InvalidDataTypeException |
|
83 | + * @throws InvalidInterfaceException |
|
84 | + * @throws InvalidArgumentException |
|
85 | + * @throws ReflectionException |
|
86 | + */ |
|
87 | + public function handle($request_data, $admin_base_url) |
|
88 | + { |
|
89 | + $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : ''; |
|
90 | + $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code); |
|
91 | + $event_ids = isset($models_and_ids_to_delete['Event']) ? $models_and_ids_to_delete['Event'] : array(); |
|
92 | + if (empty($event_ids) || !is_array($event_ids)) { |
|
93 | + throw new EE_Error( |
|
94 | + esc_html__('No Events were found to delete.', 'event_espresso') |
|
95 | + ); |
|
96 | + } |
|
97 | + $datetime_ids = isset($models_and_ids_to_delete['Datetime']) ? $models_and_ids_to_delete['Datetime'] : array(); |
|
98 | + if (!is_array($datetime_ids)) { |
|
99 | + throw new UnexpectedEntityException($datetime_ids, 'array'); |
|
100 | + } |
|
101 | + $registration_ids = isset($models_and_ids_to_delete['Registration']) ? $models_and_ids_to_delete['Registration'] : array(); |
|
102 | + if (!is_array($registration_ids)) { |
|
103 | + throw new UnexpectedEntityException($registration_ids, 'array'); |
|
104 | + } |
|
105 | + $num_registrations_to_show = 10; |
|
106 | + $reg_count = count($registration_ids); |
|
107 | + if ($reg_count > $num_registrations_to_show) { |
|
108 | + $registration_ids = array_slice($registration_ids, 0, $num_registrations_to_show); |
|
109 | + } |
|
110 | + $form = new ConfirmEventDeletionForm($event_ids); |
|
111 | + $events = $this->event_model->get_all_deleted_and_undeleted( |
|
112 | + [ |
|
113 | + [ |
|
114 | + 'EVT_ID' => ['IN', $event_ids] |
|
115 | + ] |
|
116 | + ] |
|
117 | + ); |
|
118 | + $datetimes = $this->datetime_model->get_all_deleted_and_undeleted( |
|
119 | + [ |
|
120 | + [ |
|
121 | + 'DTT_ID' => ['IN', $datetime_ids] |
|
122 | + ] |
|
123 | + ] |
|
124 | + ); |
|
125 | + $registrations = $this->registration_model->get_all_deleted_and_undeleted( |
|
126 | + [ |
|
127 | + [ |
|
128 | + 'REG_ID' => ['IN', $registration_ids] |
|
129 | + ] |
|
130 | + ] |
|
131 | + ); |
|
132 | + $confirm_deletion_args = [ |
|
133 | + 'action' => 'confirm_deletion', |
|
134 | + 'deletion_job_code' => $deletion_job_code |
|
135 | + ]; |
|
136 | + return [ |
|
137 | + 'admin_page_content' => EEH_Template::display_template( |
|
138 | + EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php', |
|
139 | + [ |
|
140 | + 'form_url' => EE_Admin_Page::add_query_args_and_nonce( |
|
141 | + $confirm_deletion_args, |
|
142 | + $admin_base_url |
|
143 | + ), |
|
144 | + 'form' => $form, |
|
145 | + 'events' => $events, |
|
146 | + 'datetimes' => $datetimes, |
|
147 | + 'registrations' => $registrations, |
|
148 | + 'reg_count' => $reg_count, |
|
149 | + 'num_registrations_to_show' => $num_registrations_to_show |
|
150 | + ], |
|
151 | + true |
|
152 | + ) |
|
153 | + ]; |
|
154 | + } |
|
155 | 155 | } |
156 | 156 | // End of file PreviewDeletion.php |
157 | 157 | // Location: EventEspresso\core\domain\services\admin\events\data/PreviewDeletion.php |