@@ -19,31 +19,31 @@ |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @var UpdateRegistrationService $update_registration_service |
|
24 | - */ |
|
25 | - private $update_registration_service; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * Command constructor |
|
30 | - * |
|
31 | - * @param UpdateRegistrationService $update_registration_service |
|
32 | - */ |
|
33 | - public function __construct( |
|
34 | - UpdateRegistrationService $update_registration_service |
|
35 | - ) { |
|
36 | - $this->update_registration_service = $update_registration_service; |
|
37 | - } |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * @param CommandInterface|UpdateRegistrationAndTransactionAfterChangeCommand $command |
|
42 | - * @return boolean |
|
43 | - * @throws InvalidEntityException |
|
44 | - */ |
|
45 | - public function handle(CommandInterface $command) |
|
46 | - { |
|
47 | - return $this->update_registration_service->updateRegistrationAndTransaction($command->registration()); |
|
48 | - } |
|
22 | + /** |
|
23 | + * @var UpdateRegistrationService $update_registration_service |
|
24 | + */ |
|
25 | + private $update_registration_service; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * Command constructor |
|
30 | + * |
|
31 | + * @param UpdateRegistrationService $update_registration_service |
|
32 | + */ |
|
33 | + public function __construct( |
|
34 | + UpdateRegistrationService $update_registration_service |
|
35 | + ) { |
|
36 | + $this->update_registration_service = $update_registration_service; |
|
37 | + } |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * @param CommandInterface|UpdateRegistrationAndTransactionAfterChangeCommand $command |
|
42 | + * @return boolean |
|
43 | + * @throws InvalidEntityException |
|
44 | + */ |
|
45 | + public function handle(CommandInterface $command) |
|
46 | + { |
|
47 | + return $this->update_registration_service->updateRegistrationAndTransaction($command->registration()); |
|
48 | + } |
|
49 | 49 | } |
@@ -23,35 +23,35 @@ |
||
23 | 23 | { |
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * @var CopyRegistrationService $copy_registration_service |
|
28 | - */ |
|
29 | - private $copy_registration_service; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * Command constructor |
|
34 | - * |
|
35 | - * @param CopyRegistrationService $copy_registration_service |
|
36 | - */ |
|
37 | - public function __construct(CopyRegistrationService $copy_registration_service) |
|
38 | - { |
|
39 | - $this->copy_registration_service = $copy_registration_service; |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @param CommandInterface|CopyRegistrationPaymentsCommand $command |
|
45 | - * @return boolean |
|
46 | - * @throws EE_Error |
|
47 | - * @throws UnexpectedEntityException |
|
48 | - * @throws RuntimeException |
|
49 | - */ |
|
50 | - public function handle(CommandInterface $command) |
|
51 | - { |
|
52 | - return $this->copy_registration_service->copyPaymentDetails( |
|
53 | - $command->targetRegistration(), |
|
54 | - $command->registrationToCopy() |
|
55 | - ); |
|
56 | - } |
|
26 | + /** |
|
27 | + * @var CopyRegistrationService $copy_registration_service |
|
28 | + */ |
|
29 | + private $copy_registration_service; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * Command constructor |
|
34 | + * |
|
35 | + * @param CopyRegistrationService $copy_registration_service |
|
36 | + */ |
|
37 | + public function __construct(CopyRegistrationService $copy_registration_service) |
|
38 | + { |
|
39 | + $this->copy_registration_service = $copy_registration_service; |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @param CommandInterface|CopyRegistrationPaymentsCommand $command |
|
45 | + * @return boolean |
|
46 | + * @throws EE_Error |
|
47 | + * @throws UnexpectedEntityException |
|
48 | + * @throws RuntimeException |
|
49 | + */ |
|
50 | + public function handle(CommandInterface $command) |
|
51 | + { |
|
52 | + return $this->copy_registration_service->copyPaymentDetails( |
|
53 | + $command->targetRegistration(), |
|
54 | + $command->registrationToCopy() |
|
55 | + ); |
|
56 | + } |
|
57 | 57 | } |
@@ -28,43 +28,43 @@ |
||
28 | 28 | { |
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * @var CancelTicketLineItemService $cancel_ticket_line_item_service |
|
33 | - */ |
|
34 | - private $cancel_ticket_line_item_service; |
|
31 | + /** |
|
32 | + * @var CancelTicketLineItemService $cancel_ticket_line_item_service |
|
33 | + */ |
|
34 | + private $cancel_ticket_line_item_service; |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * Command constructor |
|
39 | - * |
|
40 | - * @param CancelTicketLineItemService $cancel_ticket_line_item_service |
|
41 | - */ |
|
42 | - public function __construct(CancelTicketLineItemService $cancel_ticket_line_item_service) |
|
43 | - { |
|
44 | - $this->cancel_ticket_line_item_service = $cancel_ticket_line_item_service; |
|
45 | - } |
|
37 | + /** |
|
38 | + * Command constructor |
|
39 | + * |
|
40 | + * @param CancelTicketLineItemService $cancel_ticket_line_item_service |
|
41 | + */ |
|
42 | + public function __construct(CancelTicketLineItemService $cancel_ticket_line_item_service) |
|
43 | + { |
|
44 | + $this->cancel_ticket_line_item_service = $cancel_ticket_line_item_service; |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * @param CommandInterface|CancelRegistrationAndTicketLineItemCommand $command |
|
50 | - * @return boolean |
|
51 | - * @throws DomainException |
|
52 | - * @throws EE_Error |
|
53 | - * @throws EntityNotFoundException |
|
54 | - * @throws InvalidDataTypeException |
|
55 | - * @throws InvalidInterfaceException |
|
56 | - * @throws UnexpectedEntityException |
|
57 | - * @throws InvalidArgumentException |
|
58 | - * @throws ReflectionException |
|
59 | - * @throws RuntimeException |
|
60 | - */ |
|
61 | - public function handle(CommandInterface $command) |
|
62 | - { |
|
63 | - $registration = $command->registration(); |
|
64 | - $this->cancel_ticket_line_item_service->forRegistration($registration); |
|
65 | - // cancel original registration |
|
66 | - $registration->set_status(EEM_Registration::status_id_cancelled); |
|
67 | - $registration->save(); |
|
68 | - return true; |
|
69 | - } |
|
48 | + /** |
|
49 | + * @param CommandInterface|CancelRegistrationAndTicketLineItemCommand $command |
|
50 | + * @return boolean |
|
51 | + * @throws DomainException |
|
52 | + * @throws EE_Error |
|
53 | + * @throws EntityNotFoundException |
|
54 | + * @throws InvalidDataTypeException |
|
55 | + * @throws InvalidInterfaceException |
|
56 | + * @throws UnexpectedEntityException |
|
57 | + * @throws InvalidArgumentException |
|
58 | + * @throws ReflectionException |
|
59 | + * @throws RuntimeException |
|
60 | + */ |
|
61 | + public function handle(CommandInterface $command) |
|
62 | + { |
|
63 | + $registration = $command->registration(); |
|
64 | + $this->cancel_ticket_line_item_service->forRegistration($registration); |
|
65 | + // cancel original registration |
|
66 | + $registration->set_status(EEM_Registration::status_id_cancelled); |
|
67 | + $registration->save(); |
|
68 | + return true; |
|
69 | + } |
|
70 | 70 | } |
@@ -24,37 +24,37 @@ |
||
24 | 24 | { |
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * @var CopyRegistrationService $copy_registration_service |
|
29 | - */ |
|
30 | - private $copy_registration_service; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * Command constructor |
|
35 | - * |
|
36 | - * @param CopyRegistrationService $copy_registration_service |
|
37 | - */ |
|
38 | - public function __construct(CopyRegistrationService $copy_registration_service) |
|
39 | - { |
|
40 | - $this->copy_registration_service = $copy_registration_service; |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @param CommandInterface|CopyRegistrationDetailsCommand $command |
|
46 | - * @return boolean |
|
47 | - * @throws InvalidEntityException |
|
48 | - * @throws EE_Error |
|
49 | - * @throws EntityNotFoundException |
|
50 | - * @throws UnexpectedEntityException |
|
51 | - * @throws RuntimeException |
|
52 | - */ |
|
53 | - public function handle(CommandInterface $command) |
|
54 | - { |
|
55 | - return $this->copy_registration_service->copyRegistrationDetails( |
|
56 | - $command->targetRegistration(), |
|
57 | - $command->registrationToCopy() |
|
58 | - ); |
|
59 | - } |
|
27 | + /** |
|
28 | + * @var CopyRegistrationService $copy_registration_service |
|
29 | + */ |
|
30 | + private $copy_registration_service; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * Command constructor |
|
35 | + * |
|
36 | + * @param CopyRegistrationService $copy_registration_service |
|
37 | + */ |
|
38 | + public function __construct(CopyRegistrationService $copy_registration_service) |
|
39 | + { |
|
40 | + $this->copy_registration_service = $copy_registration_service; |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @param CommandInterface|CopyRegistrationDetailsCommand $command |
|
46 | + * @return boolean |
|
47 | + * @throws InvalidEntityException |
|
48 | + * @throws EE_Error |
|
49 | + * @throws EntityNotFoundException |
|
50 | + * @throws UnexpectedEntityException |
|
51 | + * @throws RuntimeException |
|
52 | + */ |
|
53 | + public function handle(CommandInterface $command) |
|
54 | + { |
|
55 | + return $this->copy_registration_service->copyRegistrationDetails( |
|
56 | + $command->targetRegistration(), |
|
57 | + $command->registrationToCopy() |
|
58 | + ); |
|
59 | + } |
|
60 | 60 | } |
@@ -18,83 +18,83 @@ discard block |
||
18 | 18 | class CommandHandlerManager implements CommandHandlerManagerInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var CommandHandlerInterface[] $command_handlers |
|
23 | - */ |
|
24 | - protected $command_handlers; |
|
21 | + /** |
|
22 | + * @var CommandHandlerInterface[] $command_handlers |
|
23 | + */ |
|
24 | + protected $command_handlers; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @type LoaderInterface $loader |
|
28 | - */ |
|
29 | - private $loader; |
|
26 | + /** |
|
27 | + * @type LoaderInterface $loader |
|
28 | + */ |
|
29 | + private $loader; |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * CommandHandlerManager constructor |
|
34 | - * |
|
35 | - * @param LoaderInterface $loader |
|
36 | - */ |
|
37 | - public function __construct(LoaderInterface $loader) |
|
38 | - { |
|
39 | - $this->loader = $loader; |
|
40 | - } |
|
32 | + /** |
|
33 | + * CommandHandlerManager constructor |
|
34 | + * |
|
35 | + * @param LoaderInterface $loader |
|
36 | + */ |
|
37 | + public function __construct(LoaderInterface $loader) |
|
38 | + { |
|
39 | + $this->loader = $loader; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * By default, Commands and CommandHandlers would normally |
|
45 | - * reside in the same folder under the same namespace, |
|
46 | - * and the names of the two classes would only differ in that |
|
47 | - * one ends in "Command" and the other ends in "CommandHandler". |
|
48 | - * However, if you wanted to utilize a CommandHandler from somewhere else, |
|
49 | - * then this method allows you to add that CommandHandler and specify the FQCN |
|
50 | - * (Fully Qualified ClassName) for the Command class that it should be used for. |
|
51 | - * For example: |
|
52 | - * by default the "Vendor\some\namespace\DoSomethingCommand" |
|
53 | - * would resolve to using "Vendor\some\namespace\DoSomethingCommandHandler" |
|
54 | - * but if you wanted to instead process that commend using: |
|
55 | - * "Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler" |
|
56 | - * then the following code: |
|
57 | - * $CommandHandlerManager = $this->loader->getShared( 'CommandHandlerManagerInterface' ); |
|
58 | - * $CommandHandlerManager->addCommandHandler( |
|
59 | - * new Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler(), |
|
60 | - * 'Vendor\some\namespace\DoSomethingCommand' |
|
61 | - * ); |
|
62 | - * would result in the alternate CommandHandler being used to process that Command |
|
63 | - * |
|
64 | - * !!! IMPORTANT !!! |
|
65 | - * If overriding the default CommandHandler for a Command, |
|
66 | - * be sure to also override CommandHandler::verify(), |
|
67 | - * or else an Exception will be thrown when the CommandBus |
|
68 | - * attempts to verify that the incoming Command matches the Handler |
|
69 | - * |
|
70 | - * @param CommandHandlerInterface $command_handler |
|
71 | - * @param string $fqcn_for_command Fully Qualified ClassName for Command |
|
72 | - * @return void |
|
73 | - * @throws InvalidCommandHandlerException |
|
74 | - */ |
|
75 | - public function addCommandHandler(CommandHandlerInterface $command_handler, $fqcn_for_command = '') |
|
76 | - { |
|
77 | - $command = ! empty($fqcn_for_command) |
|
78 | - ? $fqcn_for_command |
|
79 | - : str_replace('CommandHandler', 'Command', get_class($command_handler)); |
|
80 | - if (empty($command)) { |
|
81 | - throw new InvalidCommandHandlerException($command); |
|
82 | - } |
|
83 | - $this->command_handlers[ $command ] = $command_handler; |
|
84 | - } |
|
43 | + /** |
|
44 | + * By default, Commands and CommandHandlers would normally |
|
45 | + * reside in the same folder under the same namespace, |
|
46 | + * and the names of the two classes would only differ in that |
|
47 | + * one ends in "Command" and the other ends in "CommandHandler". |
|
48 | + * However, if you wanted to utilize a CommandHandler from somewhere else, |
|
49 | + * then this method allows you to add that CommandHandler and specify the FQCN |
|
50 | + * (Fully Qualified ClassName) for the Command class that it should be used for. |
|
51 | + * For example: |
|
52 | + * by default the "Vendor\some\namespace\DoSomethingCommand" |
|
53 | + * would resolve to using "Vendor\some\namespace\DoSomethingCommandHandler" |
|
54 | + * but if you wanted to instead process that commend using: |
|
55 | + * "Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler" |
|
56 | + * then the following code: |
|
57 | + * $CommandHandlerManager = $this->loader->getShared( 'CommandHandlerManagerInterface' ); |
|
58 | + * $CommandHandlerManager->addCommandHandler( |
|
59 | + * new Vendor\a\totally\different\namespace\for\DoSomethingCommandHandler(), |
|
60 | + * 'Vendor\some\namespace\DoSomethingCommand' |
|
61 | + * ); |
|
62 | + * would result in the alternate CommandHandler being used to process that Command |
|
63 | + * |
|
64 | + * !!! IMPORTANT !!! |
|
65 | + * If overriding the default CommandHandler for a Command, |
|
66 | + * be sure to also override CommandHandler::verify(), |
|
67 | + * or else an Exception will be thrown when the CommandBus |
|
68 | + * attempts to verify that the incoming Command matches the Handler |
|
69 | + * |
|
70 | + * @param CommandHandlerInterface $command_handler |
|
71 | + * @param string $fqcn_for_command Fully Qualified ClassName for Command |
|
72 | + * @return void |
|
73 | + * @throws InvalidCommandHandlerException |
|
74 | + */ |
|
75 | + public function addCommandHandler(CommandHandlerInterface $command_handler, $fqcn_for_command = '') |
|
76 | + { |
|
77 | + $command = ! empty($fqcn_for_command) |
|
78 | + ? $fqcn_for_command |
|
79 | + : str_replace('CommandHandler', 'Command', get_class($command_handler)); |
|
80 | + if (empty($command)) { |
|
81 | + throw new InvalidCommandHandlerException($command); |
|
82 | + } |
|
83 | + $this->command_handlers[ $command ] = $command_handler; |
|
84 | + } |
|
85 | 85 | |
86 | 86 | |
87 | - /** |
|
88 | - * @param CommandInterface $command |
|
89 | - * @param CommandBusInterface $command_bus |
|
90 | - * @return mixed |
|
91 | - * @throws DomainException |
|
92 | - * @throws CommandHandlerNotFoundException |
|
93 | - */ |
|
94 | - public function getCommandHandler(CommandInterface $command, CommandBusInterface $command_bus = null) |
|
95 | - { |
|
96 | - $command_name = get_class($command); |
|
97 | - /* |
|
87 | + /** |
|
88 | + * @param CommandInterface $command |
|
89 | + * @param CommandBusInterface $command_bus |
|
90 | + * @return mixed |
|
91 | + * @throws DomainException |
|
92 | + * @throws CommandHandlerNotFoundException |
|
93 | + */ |
|
94 | + public function getCommandHandler(CommandInterface $command, CommandBusInterface $command_bus = null) |
|
95 | + { |
|
96 | + $command_name = get_class($command); |
|
97 | + /* |
|
98 | 98 | * Filters the Fully Qualified Class Name for the Command Handler |
99 | 99 | * that will be used to handle the incoming Command |
100 | 100 | * |
@@ -107,34 +107,34 @@ discard block |
||
107 | 107 | * @param string "CommandHandler::class" Fully Qualified Class Name for the Command Handler |
108 | 108 | * @param CommandInterface $command the actual Command instance |
109 | 109 | */ |
110 | - $command_handler = apply_filters( |
|
111 | - 'FHEE__EventEspresso_core_services_commands_CommandHandlerManager__getCommandHandler__command_handler', |
|
112 | - str_replace('Command', 'CommandHandler', $command_name), |
|
113 | - $command |
|
114 | - ); |
|
115 | - $handler = null; |
|
116 | - // has a command handler already been set for this class ? |
|
117 | - // if not, can we find one via the FQCN ? |
|
118 | - if (isset($this->command_handlers[ $command_name ])) { |
|
119 | - $handler = $this->command_handlers[ $command_name ]; |
|
120 | - } elseif (class_exists($command_handler)) { |
|
121 | - $handler = $this->loader->getShared($command_handler); |
|
122 | - } |
|
123 | - // if Handler requires an instance of the CommandBus, but that has not yet been set |
|
124 | - if ($handler instanceof CompositeCommandHandler && ! $handler->commandBus() instanceof CommandBusInterface) { |
|
125 | - if (! $command_bus instanceof CommandBusInterface) { |
|
126 | - throw new DomainException( |
|
127 | - esc_html__( |
|
128 | - 'CompositeCommandHandler classes require an instance of the CommandBus.', |
|
129 | - 'event_espresso' |
|
130 | - ) |
|
131 | - ); |
|
132 | - } |
|
133 | - $handler->setCommandBus($command_bus); |
|
134 | - } |
|
135 | - if ($handler instanceof CommandHandlerInterface) { |
|
136 | - return $handler; |
|
137 | - } |
|
138 | - throw new CommandHandlerNotFoundException($command_handler); |
|
139 | - } |
|
110 | + $command_handler = apply_filters( |
|
111 | + 'FHEE__EventEspresso_core_services_commands_CommandHandlerManager__getCommandHandler__command_handler', |
|
112 | + str_replace('Command', 'CommandHandler', $command_name), |
|
113 | + $command |
|
114 | + ); |
|
115 | + $handler = null; |
|
116 | + // has a command handler already been set for this class ? |
|
117 | + // if not, can we find one via the FQCN ? |
|
118 | + if (isset($this->command_handlers[ $command_name ])) { |
|
119 | + $handler = $this->command_handlers[ $command_name ]; |
|
120 | + } elseif (class_exists($command_handler)) { |
|
121 | + $handler = $this->loader->getShared($command_handler); |
|
122 | + } |
|
123 | + // if Handler requires an instance of the CommandBus, but that has not yet been set |
|
124 | + if ($handler instanceof CompositeCommandHandler && ! $handler->commandBus() instanceof CommandBusInterface) { |
|
125 | + if (! $command_bus instanceof CommandBusInterface) { |
|
126 | + throw new DomainException( |
|
127 | + esc_html__( |
|
128 | + 'CompositeCommandHandler classes require an instance of the CommandBus.', |
|
129 | + 'event_espresso' |
|
130 | + ) |
|
131 | + ); |
|
132 | + } |
|
133 | + $handler->setCommandBus($command_bus); |
|
134 | + } |
|
135 | + if ($handler instanceof CommandHandlerInterface) { |
|
136 | + return $handler; |
|
137 | + } |
|
138 | + throw new CommandHandlerNotFoundException($command_handler); |
|
139 | + } |
|
140 | 140 | } |
@@ -34,74 +34,74 @@ |
||
34 | 34 | class CommandBus implements CommandBusInterface |
35 | 35 | { |
36 | 36 | |
37 | - /** |
|
38 | - * @type CommandHandlerManagerInterface $command_handler_manager |
|
39 | - */ |
|
40 | - private $command_handler_manager; |
|
37 | + /** |
|
38 | + * @type CommandHandlerManagerInterface $command_handler_manager |
|
39 | + */ |
|
40 | + private $command_handler_manager; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @type CommandBusMiddlewareInterface[] $command_bus_middleware |
|
44 | - */ |
|
45 | - private $command_bus_middleware; |
|
42 | + /** |
|
43 | + * @type CommandBusMiddlewareInterface[] $command_bus_middleware |
|
44 | + */ |
|
45 | + private $command_bus_middleware; |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * CommandBus constructor |
|
50 | - * |
|
51 | - * @param CommandHandlerManagerInterface $command_handler_manager |
|
52 | - * @param CommandBusMiddlewareInterface[] $command_bus_middleware |
|
53 | - */ |
|
54 | - public function __construct( |
|
55 | - CommandHandlerManagerInterface $command_handler_manager, |
|
56 | - array $command_bus_middleware = array() |
|
57 | - ) { |
|
58 | - $this->command_handler_manager = $command_handler_manager; |
|
59 | - $this->command_bus_middleware = is_array($command_bus_middleware) |
|
60 | - ? $command_bus_middleware |
|
61 | - : array($command_bus_middleware); |
|
62 | - } |
|
48 | + /** |
|
49 | + * CommandBus constructor |
|
50 | + * |
|
51 | + * @param CommandHandlerManagerInterface $command_handler_manager |
|
52 | + * @param CommandBusMiddlewareInterface[] $command_bus_middleware |
|
53 | + */ |
|
54 | + public function __construct( |
|
55 | + CommandHandlerManagerInterface $command_handler_manager, |
|
56 | + array $command_bus_middleware = array() |
|
57 | + ) { |
|
58 | + $this->command_handler_manager = $command_handler_manager; |
|
59 | + $this->command_bus_middleware = is_array($command_bus_middleware) |
|
60 | + ? $command_bus_middleware |
|
61 | + : array($command_bus_middleware); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * @return CommandHandlerManagerInterface |
|
67 | - */ |
|
68 | - public function getCommandHandlerManager() |
|
69 | - { |
|
70 | - return $this->command_handler_manager; |
|
71 | - } |
|
65 | + /** |
|
66 | + * @return CommandHandlerManagerInterface |
|
67 | + */ |
|
68 | + public function getCommandHandlerManager() |
|
69 | + { |
|
70 | + return $this->command_handler_manager; |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | - /** |
|
75 | - * @param CommandInterface $command |
|
76 | - * @return mixed |
|
77 | - * @throws InvalidDataTypeException |
|
78 | - * @throws InvalidCommandBusMiddlewareException |
|
79 | - */ |
|
80 | - public function execute($command) |
|
81 | - { |
|
82 | - if (! $command instanceof CommandInterface) { |
|
83 | - throw new InvalidDataTypeException(__METHOD__ . '( $command )', $command, 'CommandInterface'); |
|
84 | - } |
|
85 | - // we're going to add the Command Handler as a callable |
|
86 | - // that will get run at the end of our middleware stack |
|
87 | - // can't pass $this to a Closure, so use a named variable |
|
88 | - $command_bus = $this; |
|
89 | - $middleware = static function ($command) use ($command_bus) { |
|
90 | - return $command_bus->getCommandHandlerManager() |
|
91 | - ->getCommandHandler($command, $command_bus) |
|
92 | - ->verify($command) |
|
93 | - ->handle($command); |
|
94 | - }; |
|
95 | - // now build the rest of the middleware stack |
|
96 | - while ($command_bus_middleware = array_pop($this->command_bus_middleware)) { |
|
97 | - if (! $command_bus_middleware instanceof CommandBusMiddlewareInterface) { |
|
98 | - throw new InvalidCommandBusMiddlewareException($command_bus_middleware); |
|
99 | - } |
|
100 | - $middleware = static function ($command) use ($command_bus_middleware, $middleware) { |
|
101 | - return $command_bus_middleware->handle($command, $middleware); |
|
102 | - }; |
|
103 | - } |
|
104 | - // and finally, pass the command into the stack and return the results |
|
105 | - return $middleware($command); |
|
106 | - } |
|
74 | + /** |
|
75 | + * @param CommandInterface $command |
|
76 | + * @return mixed |
|
77 | + * @throws InvalidDataTypeException |
|
78 | + * @throws InvalidCommandBusMiddlewareException |
|
79 | + */ |
|
80 | + public function execute($command) |
|
81 | + { |
|
82 | + if (! $command instanceof CommandInterface) { |
|
83 | + throw new InvalidDataTypeException(__METHOD__ . '( $command )', $command, 'CommandInterface'); |
|
84 | + } |
|
85 | + // we're going to add the Command Handler as a callable |
|
86 | + // that will get run at the end of our middleware stack |
|
87 | + // can't pass $this to a Closure, so use a named variable |
|
88 | + $command_bus = $this; |
|
89 | + $middleware = static function ($command) use ($command_bus) { |
|
90 | + return $command_bus->getCommandHandlerManager() |
|
91 | + ->getCommandHandler($command, $command_bus) |
|
92 | + ->verify($command) |
|
93 | + ->handle($command); |
|
94 | + }; |
|
95 | + // now build the rest of the middleware stack |
|
96 | + while ($command_bus_middleware = array_pop($this->command_bus_middleware)) { |
|
97 | + if (! $command_bus_middleware instanceof CommandBusMiddlewareInterface) { |
|
98 | + throw new InvalidCommandBusMiddlewareException($command_bus_middleware); |
|
99 | + } |
|
100 | + $middleware = static function ($command) use ($command_bus_middleware, $middleware) { |
|
101 | + return $command_bus_middleware->handle($command, $middleware); |
|
102 | + }; |
|
103 | + } |
|
104 | + // and finally, pass the command into the stack and return the results |
|
105 | + return $middleware($command); |
|
106 | + } |
|
107 | 107 | } |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function execute($command) |
81 | 81 | { |
82 | - if (! $command instanceof CommandInterface) { |
|
83 | - throw new InvalidDataTypeException(__METHOD__ . '( $command )', $command, 'CommandInterface'); |
|
82 | + if ( ! $command instanceof CommandInterface) { |
|
83 | + throw new InvalidDataTypeException(__METHOD__.'( $command )', $command, 'CommandInterface'); |
|
84 | 84 | } |
85 | 85 | // we're going to add the Command Handler as a callable |
86 | 86 | // that will get run at the end of our middleware stack |
87 | 87 | // can't pass $this to a Closure, so use a named variable |
88 | 88 | $command_bus = $this; |
89 | - $middleware = static function ($command) use ($command_bus) { |
|
89 | + $middleware = static function($command) use ($command_bus) { |
|
90 | 90 | return $command_bus->getCommandHandlerManager() |
91 | 91 | ->getCommandHandler($command, $command_bus) |
92 | 92 | ->verify($command) |
@@ -94,10 +94,10 @@ discard block |
||
94 | 94 | }; |
95 | 95 | // now build the rest of the middleware stack |
96 | 96 | while ($command_bus_middleware = array_pop($this->command_bus_middleware)) { |
97 | - if (! $command_bus_middleware instanceof CommandBusMiddlewareInterface) { |
|
97 | + if ( ! $command_bus_middleware instanceof CommandBusMiddlewareInterface) { |
|
98 | 98 | throw new InvalidCommandBusMiddlewareException($command_bus_middleware); |
99 | 99 | } |
100 | - $middleware = static function ($command) use ($command_bus_middleware, $middleware) { |
|
100 | + $middleware = static function($command) use ($command_bus_middleware, $middleware) { |
|
101 | 101 | return $command_bus_middleware->handle($command, $middleware); |
102 | 102 | }; |
103 | 103 | } |
@@ -556,8 +556,8 @@ discard block |
||
556 | 556 | * that they WILL be added (because the attendees stage runs nearly last during |
557 | 557 | * the migration script) |
558 | 558 | * @param type $new_ticket_id |
559 | - * @param type $sold |
|
560 | - * @param type $STS_ID |
|
559 | + * @param string $STS_ID |
|
560 | + * @param integer $quantity_sold |
|
561 | 561 | * @return boolean whether they were successfully updated or not |
562 | 562 | */ |
563 | 563 | protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID) |
@@ -757,6 +757,9 @@ discard block |
||
757 | 757 | return $count; |
758 | 758 | } |
759 | 759 | |
760 | + /** |
|
761 | + * @param integer $new_txn_id |
|
762 | + */ |
|
760 | 763 | private function _insert_new_payment($old_attendee, $new_txn_id) |
761 | 764 | { |
762 | 765 | global $wpdb; |
@@ -183,645 +183,645 @@ |
||
183 | 183 | */ |
184 | 184 | class EE_DMS_4_1_0_attendees extends EE_Data_Migration_Script_Stage_Table |
185 | 185 | { |
186 | - private $_new_attendee_cpt_table; |
|
187 | - private $_new_attendee_meta_table; |
|
188 | - private $_new_reg_table; |
|
189 | - private $_new_transaction_table; |
|
190 | - private $_new_payment_table; |
|
191 | - private $_new_line_table; |
|
192 | - private $_old_mer_table; |
|
193 | - private $_new_ticket_table; |
|
194 | - private $_new_ticket_datetime_table; |
|
195 | - private $_new_datetime_table; |
|
196 | - private $_new_datetime_ticket_table; |
|
197 | - private $_new_price_table; |
|
198 | - private $_new_ticket_price_table; |
|
199 | - /** |
|
200 | - * Rememebrs whether or not the mer table exists |
|
201 | - * @var boolean |
|
202 | - */ |
|
203 | - private $_mer_tables_exist = null; |
|
204 | - |
|
205 | - public function __construct() |
|
206 | - { |
|
207 | - global $wpdb; |
|
208 | - $this->_pretty_name = __("Attendees", "event_espresso"); |
|
209 | - $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
210 | - // Only select the event status column from the event table. |
|
211 | - $this->select_expression = 'att.*, e.event_status'; |
|
212 | - // Only select attendees for events that aren't deleted. |
|
213 | - $this->_extra_where_sql = 'AS att |
|
186 | + private $_new_attendee_cpt_table; |
|
187 | + private $_new_attendee_meta_table; |
|
188 | + private $_new_reg_table; |
|
189 | + private $_new_transaction_table; |
|
190 | + private $_new_payment_table; |
|
191 | + private $_new_line_table; |
|
192 | + private $_old_mer_table; |
|
193 | + private $_new_ticket_table; |
|
194 | + private $_new_ticket_datetime_table; |
|
195 | + private $_new_datetime_table; |
|
196 | + private $_new_datetime_ticket_table; |
|
197 | + private $_new_price_table; |
|
198 | + private $_new_ticket_price_table; |
|
199 | + /** |
|
200 | + * Rememebrs whether or not the mer table exists |
|
201 | + * @var boolean |
|
202 | + */ |
|
203 | + private $_mer_tables_exist = null; |
|
204 | + |
|
205 | + public function __construct() |
|
206 | + { |
|
207 | + global $wpdb; |
|
208 | + $this->_pretty_name = __("Attendees", "event_espresso"); |
|
209 | + $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
210 | + // Only select the event status column from the event table. |
|
211 | + $this->select_expression = 'att.*, e.event_status'; |
|
212 | + // Only select attendees for events that aren't deleted. |
|
213 | + $this->_extra_where_sql = 'AS att |
|
214 | 214 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
215 | 215 | WHERE e.event_status!="D"'; |
216 | - $this->_old_mer_table = $wpdb->prefix . "events_multi_event_registration_id_group"; |
|
217 | - $this->_new_attendee_cpt_table = $wpdb->posts; |
|
218 | - $this->_new_attendee_meta_table = $wpdb->prefix . "esp_attendee_meta"; |
|
219 | - $this->_new_reg_table = $wpdb->prefix . "esp_registration"; |
|
220 | - $this->_new_transaction_table = $wpdb->prefix . "esp_transaction"; |
|
221 | - $this->_new_payment_table = $wpdb->prefix . "esp_payment"; |
|
222 | - $this->_new_line_table = $wpdb->prefix . "esp_line_item"; |
|
223 | - $this->_new_ticket_table = $wpdb->prefix . "esp_ticket"; |
|
224 | - $this->_new_ticket_datetime_table = $wpdb->prefix . "esp_datetime_ticket"; |
|
225 | - $this->_new_datetime_table = $wpdb->prefix . "esp_datetime"; |
|
226 | - $this->_new_datetime_ticket_table = $wpdb->prefix . "esp_datetime_ticket"; |
|
227 | - $this->_new_price_table = $wpdb->prefix . "esp_price"; |
|
228 | - $this->_new_ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
229 | - parent::__construct(); |
|
230 | - } |
|
231 | - |
|
232 | - protected function _migrate_old_row($old_row) |
|
233 | - { |
|
234 | - // first check if there's already a new attendee with similar characteristics |
|
235 | - $new_att_id = $this->_find_attendee_cpt_matching($old_row); |
|
236 | - if (!$new_att_id) { |
|
237 | - $new_att_id = $this->_insert_new_attendee_cpt($old_row); |
|
238 | - if (!$new_att_id) { |
|
239 | - // if we couldnt even make an attendee, abandon all hope |
|
240 | - return false; |
|
241 | - } |
|
242 | - $new_att_meta_id = $this->_insert_attendee_meta_row($old_row, $new_att_id); |
|
243 | - if ($new_att_meta_id) { |
|
244 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_meta_table, $new_att_meta_id); |
|
245 | - } |
|
246 | - } |
|
247 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id); |
|
248 | - |
|
249 | - $txn_id = $this->_insert_new_transaction($old_row); |
|
250 | - if (!$txn_id) { |
|
251 | - // if we couldnt make the transaction, also abandon all hope |
|
252 | - return false; |
|
253 | - } |
|
254 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_transaction_table, $txn_id); |
|
255 | - $pay_id = $this->_insert_new_payment($old_row, $txn_id); |
|
256 | - if ($pay_id) { |
|
257 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_payment_table, $pay_id); |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - // even if there was no payment, we can go ahead with adding the reg |
|
262 | - $new_regs = $this->_insert_new_registrations($old_row, $new_att_id, $txn_id); |
|
263 | - if ($new_regs) { |
|
264 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_reg_table, $new_regs); |
|
265 | - } |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * Checks if there's already an attendee CPT in the db that has the same |
|
270 | - * first and last name, and email. If so, returns its ID as an int. |
|
271 | - * @global type $wpdb |
|
272 | - * @param array $old_attendee |
|
273 | - * @return int |
|
274 | - */ |
|
275 | - private function _find_attendee_cpt_matching($old_attendee) |
|
276 | - { |
|
277 | - global $wpdb; |
|
278 | - $existing_attendee_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . $this->_new_attendee_cpt_table . " AS cpt INNER JOIN " . $this->_new_attendee_meta_table . " AS meta ON cpt.ID = meta.ATT_ID WHERE meta.ATT_fname = %s AND meta.ATT_lname = %s AND meta.ATT_email = %s LIMIT 1", $old_attendee['fname'], $old_attendee['lname'], $old_attendee['email'])); |
|
279 | - return intval($existing_attendee_id); |
|
280 | - } |
|
281 | - |
|
282 | - private function _insert_new_attendee_cpt($old_attendee) |
|
283 | - { |
|
284 | - global $wpdb; |
|
285 | - $cols_n_values = array( |
|
286 | - 'post_title' => stripslashes($old_attendee['fname'] . " " . $old_attendee['lname']),// ATT_full_name |
|
287 | - 'post_content' => '',// ATT_bio |
|
288 | - 'post_name' => sanitize_title($old_attendee['fname'] . "-" . $old_attendee['lname']),// ATT_slug |
|
289 | - 'post_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created |
|
290 | - 'post_excerpt' => '',// ATT_short_bio |
|
291 | - 'post_modified' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified |
|
292 | - 'post_author' => 0,// ATT_author |
|
293 | - 'post_parent' => 0,// ATT_parent |
|
294 | - 'post_type' => 'espresso_attendees',// post_type |
|
295 | - 'post_status' => 'publish'// status |
|
296 | - ); |
|
297 | - $datatypes = array( |
|
298 | - '%s',// ATT_full_name |
|
299 | - '%s',// ATT_bio |
|
300 | - '%s',// ATT_slug |
|
301 | - '%s',// ATT_created |
|
302 | - '%s',// ATT_short_bio |
|
303 | - '%s',// ATT_modified |
|
304 | - '%d',// ATT_author |
|
305 | - '%d',// ATT_parent |
|
306 | - '%s',// post_type |
|
307 | - '%s',// status |
|
308 | - ); |
|
309 | - $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes); |
|
310 | - if (!$success) { |
|
311 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
|
312 | - return 0; |
|
313 | - } |
|
314 | - $new_id = $wpdb->insert_id; |
|
315 | - return $new_id; |
|
316 | - } |
|
317 | - |
|
318 | - private function _insert_attendee_meta_row($old_attendee, $new_attendee_cpt_id) |
|
319 | - { |
|
320 | - global $wpdb; |
|
321 | - // get the state and country ids from the old row |
|
322 | - try { |
|
323 | - $new_country = $this->get_migration_script()->get_or_create_country(stripslashes($old_attendee['country_id'])); |
|
324 | - $new_country_iso = $new_country['CNT_ISO']; |
|
325 | - } catch (EE_Error $exception) { |
|
326 | - $new_country_iso = $this->get_migration_script()->get_default_country_iso(); |
|
327 | - } |
|
328 | - try { |
|
329 | - $new_state = $this->get_migration_script()->get_or_create_state(stripslashes($old_attendee['state']), $new_country_iso); |
|
330 | - $new_state_id = $new_state['STA_ID']; |
|
331 | - } catch (EE_Error $exception) { |
|
332 | - $new_state_id = 0; |
|
333 | - } |
|
334 | - $cols_n_values = array( |
|
335 | - 'ATT_ID' => $new_attendee_cpt_id, |
|
336 | - 'ATT_fname' => stripslashes($old_attendee['fname']), |
|
337 | - 'ATT_lname' => stripslashes($old_attendee['lname']), |
|
338 | - 'ATT_address' => stripslashes($old_attendee['address']), |
|
339 | - 'ATT_address2' => stripslashes($old_attendee['address2']), |
|
340 | - 'ATT_city' => stripslashes($old_attendee['city']), |
|
341 | - 'STA_ID' => $new_state_id, |
|
342 | - 'CNT_ISO' => $new_country_iso, |
|
343 | - 'ATT_zip' => stripslashes($old_attendee['zip']), |
|
344 | - 'ATT_email' => stripslashes($old_attendee['email']), |
|
345 | - 'ATT_phone' => stripslashes($old_attendee['phone']), |
|
346 | - ); |
|
347 | - $datatypes = array( |
|
348 | - '%d',// ATT_ID |
|
349 | - '%s',// ATT_fname |
|
350 | - '%s',// ATT_lname |
|
351 | - '%s',// ATT_address |
|
352 | - '%s',// ATT_address2 |
|
353 | - '%s',// ATT_city |
|
354 | - '%d',// STA_ID |
|
355 | - '%s',// CNT_ISO |
|
356 | - '%s',// ATT_zip |
|
357 | - '%s',// ATT_email |
|
358 | - '%s',// ATT_phone |
|
359 | - ); |
|
360 | - $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes); |
|
361 | - if (!$success) { |
|
362 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_meta_table, $cols_n_values, $datatypes)); |
|
363 | - return 0; |
|
364 | - } |
|
365 | - $new_id = $wpdb->insert_id; |
|
366 | - return $new_id; |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * Note: we don't necessarily create a new transaction for each attendee row. |
|
371 | - * Only if the old attendee 'is_primary' is true; otherwise we find the old attendee row that |
|
372 | - * 'is_primary' and has the same 'txn_id', then we return ITS new transaction id |
|
373 | - * @global type $wpdb |
|
374 | - * @param type $old_attendee |
|
375 | - * @return int new transaction id |
|
376 | - */ |
|
377 | - private function _insert_new_transaction($old_attendee) |
|
378 | - { |
|
379 | - global $wpdb; |
|
380 | - |
|
381 | - // first: let's check for an existing transaction for this old attendee |
|
382 | - if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn |
|
383 | - $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table); |
|
384 | - } else { // non-primary attendee, so find its primary attendee's transaction |
|
385 | - $primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . $this->_old_table . " WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id'])); |
|
386 | - if (!$primary_attendee_old_id) { |
|
387 | - $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']); |
|
388 | - $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null; |
|
389 | - } |
|
390 | - $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table); |
|
391 | - if (!$txn_id) { |
|
392 | - $this->add_error(sprintf(__("Could not find primary attendee's new transaction. Current attendee is: %s, we think the 3.1 primary attendee for it has id %d, but there's no 4.1 transaction for that primary attendee id.", "event_espresso"), $this->_json_encode($old_attendee), $primary_attendee_old_id)); |
|
393 | - $txn_id = 0; |
|
394 | - } |
|
395 | - } |
|
396 | - // if there isn't yet a transaction row for this, create one |
|
397 | - // (so even if it was a non-primary attendee with no EE3 primary attendee, |
|
398 | - // it ought to have SOME transaction, so we'll make one) |
|
399 | - if (!$txn_id) { |
|
400 | - // maps 3.1 payment stati onto 4.1 transaction stati |
|
401 | - $txn_status_mapping = array( |
|
402 | - 'Completed' => 'TCM', |
|
403 | - 'Pending' => 'TIN', |
|
404 | - 'Payment Declined' => 'TIN', |
|
405 | - 'Incomplete' => 'TIN', |
|
406 | - 'Not Completed' => 'TIN', |
|
407 | - 'Cancelled' => 'TIN', |
|
408 | - 'Declined' => 'TIN' |
|
409 | - ); |
|
410 | - $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN'; |
|
411 | - $cols_n_values = array( |
|
412 | - 'TXN_timestamp' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
413 | - 'TXN_total' => floatval($old_attendee['total_cost']), |
|
414 | - 'TXN_paid' => floatval($old_attendee['amount_pd']), |
|
415 | - 'STS_ID' => $STS_ID, |
|
416 | - 'TXN_hash_salt' => $old_attendee['hashSalt'] |
|
417 | - ); |
|
418 | - $datatypes = array( |
|
419 | - '%s',// TXN_timestamp |
|
420 | - '%f',// TXN_total |
|
421 | - '%f',// TXN_paid |
|
422 | - '%s',// STS_ID |
|
423 | - '%s',// TXN_hash_salt |
|
424 | - ); |
|
425 | - $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes); |
|
426 | - if (!$success) { |
|
427 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_transaction_table, $cols_n_values, $datatypes)); |
|
428 | - return 0; |
|
429 | - } |
|
430 | - $txn_id = $wpdb->insert_id; |
|
431 | - } |
|
432 | - |
|
433 | - return $txn_id; |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * Detects if the MER tables exist |
|
438 | - * @global type $wpdb |
|
439 | - * @return boolean |
|
440 | - */ |
|
441 | - private function _mer_tables_exist() |
|
442 | - { |
|
443 | - if ($this->_mer_tables_exist === null) { |
|
444 | - global $wpdb; |
|
445 | - |
|
446 | - if ($wpdb->get_var("SHOW TABLES LIKE '{$this->_old_mer_table}'") != $this->_old_mer_table) { |
|
447 | - $this->_mer_tables_exist = false; |
|
448 | - } else { |
|
449 | - $this->_mer_tables_exist = true; |
|
450 | - } |
|
451 | - } |
|
452 | - return $this->_mer_tables_exist; |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Gets the 4.1 registration's status given the 3.1 attendee row. We consider |
|
457 | - * whether the event required pre-approval or not,a dn the 4.1 payment status. |
|
458 | - * @global type $wpdb |
|
459 | - * @param type $old_attendee_row |
|
460 | - * @return string |
|
461 | - */ |
|
462 | - private function _get_reg_status_for_old_payment_status($old_attendee_row) |
|
463 | - { |
|
464 | - // need event default reg status and if pre_approval was required |
|
465 | - global $wpdb; |
|
466 | - $event_required_pre_approval = $wpdb->get_var($wpdb->prepare("SELECT require_pre_approval FROM " . $wpdb->prefix . "events_detail WHERE id = %d", $old_attendee_row['event_id'])); |
|
467 | - return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID( |
|
468 | - $old_attendee_row['payment_status'], |
|
469 | - intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve']) |
|
470 | - ); |
|
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * Adds however many rgistrations are indicated by the old attendee's QUANTITY field, |
|
475 | - * and returns an array of their IDs |
|
476 | - * @global type $wpdb |
|
477 | - * @param array $old_attendee |
|
478 | - * @param int $new_attendee_id |
|
479 | - * @param int $new_txn_id |
|
480 | - * @return array of new registratio ids |
|
481 | - */ |
|
482 | - private function _insert_new_registrations($old_attendee, $new_attendee_id, $new_txn_id) |
|
483 | - { |
|
484 | - global $wpdb; |
|
485 | - |
|
486 | - $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee); |
|
487 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . 'events_detail', $old_attendee['event_id'], $wpdb->posts); |
|
488 | - if (!$new_event_id) { |
|
489 | - $this->add_error(sprintf(__("Could not find NEW event CPT ID for old event '%d' on old attendee %s", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee))); |
|
490 | - } |
|
491 | - |
|
492 | - $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id); |
|
493 | - if (!$ticket_id) { |
|
494 | - $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id); |
|
495 | - $this->add_error(sprintf(__('Could not find a ticket for old attendee with id %d for new event %d, so created a new ticket with id %d', 'event_espresso'), $old_attendee['id'], $new_event_id, $ticket_id)); |
|
496 | - } |
|
497 | - $regs_on_this_row = intval($old_attendee['quantity']); |
|
498 | - $new_regs = array(); |
|
499 | - // 4 cases we need to account for: |
|
500 | - // 1 old attendee_details row with a quantity of X (no mer) |
|
501 | - // Y old attendee_details rows with a quantity of 1 (no mer) joined by their common registration_id |
|
502 | - // Y old attendee_details rows with a quantity of x (because of mer) |
|
503 | - // Y old attendee_details rows with a quantity of 1 (because of mer) joined by wp_events_multi_event_registration_id_group |
|
504 | - for ($count = 1; $count <= $regs_on_this_row; $count++) { |
|
505 | - // sum regs on older rows |
|
506 | - $regs_on_this_event_and_txn = $this->_sum_old_attendees_on_old_txn($old_attendee, true); |
|
507 | - $cols_n_values = array( |
|
508 | - 'EVT_ID' => $new_event_id, |
|
509 | - 'ATT_ID' => $new_attendee_id, |
|
510 | - 'TXN_ID' => $new_txn_id, |
|
511 | - 'TKT_ID' => $ticket_id, |
|
512 | - 'STS_ID' => $STS_ID, |
|
513 | - 'REG_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
514 | - 'REG_final_price' => $old_attendee['final_price'], |
|
515 | - 'REG_session' => substr($old_attendee['attendee_session'], 0, 44), |
|
516 | - 'REG_code' => sanitize_key($old_attendee['registration_id']), |
|
517 | - 'REG_url_link' => sanitize_key($old_attendee['registration_id'] . '-' . $count), |
|
518 | - 'REG_count' => $regs_on_this_event_and_txn + $count, |
|
519 | - 'REG_group_size' => $this->_sum_old_attendees_on_old_txn($old_attendee, false), |
|
520 | - 'REG_att_is_going' => true, |
|
521 | - 'REG_deleted' => false |
|
522 | - ); |
|
523 | - $datatypes = array( |
|
524 | - '%d',// EVT_ID |
|
525 | - '%d',// ATT_ID |
|
526 | - '%d',// TXN_ID |
|
527 | - '%d',// TKT_ID |
|
528 | - '%s',// STS_ID |
|
529 | - '%s',// REG_date |
|
530 | - '%f',// REG_final_price |
|
531 | - '%s',// REG_session |
|
532 | - '%s',// REG_code |
|
533 | - '%s',// REG_url_link |
|
534 | - '%d',// REG_count |
|
535 | - '%d',// REG_group_size |
|
536 | - '%d',// REG_att_is_going |
|
537 | - '%d',// REG_deleted |
|
538 | - ); |
|
539 | - $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes); |
|
540 | - if (!$success) { |
|
541 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes)); |
|
542 | - return 0; |
|
543 | - } |
|
544 | - $cols_n_values['REG_ID'] = $wpdb->insert_id; |
|
545 | - $new_regs[] = $wpdb->insert_id; |
|
546 | - } |
|
547 | - $this->_add_regs_to_ticket_and_datetimes($ticket_id, count($new_regs), $STS_ID); |
|
548 | - return $new_regs; |
|
549 | - } |
|
550 | - |
|
551 | - /** |
|
552 | - * Increments the sold values on the ticket and its related datetimes by the amount sold, |
|
553 | - * which should be done directly after adding the rows. Yes this means we're constantly incrementing |
|
554 | - * the sold amounts as we go, and is less efficient than a single big query, |
|
555 | - * but its safer because we KNOW these regs have been added, rather than inferring |
|
556 | - * that they WILL be added (because the attendees stage runs nearly last during |
|
557 | - * the migration script) |
|
558 | - * @param type $new_ticket_id |
|
559 | - * @param type $sold |
|
560 | - * @param type $STS_ID |
|
561 | - * @return boolean whether they were successfully updated or not |
|
562 | - */ |
|
563 | - protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID) |
|
564 | - { |
|
565 | - if ($STS_ID != 'RAP') { |
|
566 | - return true; |
|
567 | - } |
|
568 | - global $wpdb; |
|
569 | - $success = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} SET TKT_sold=TKT_sold+%d WHERE TKT_ID=%d", $quantity_sold, $new_ticket_id)); |
|
570 | - if ($success) { |
|
571 | - // get the ticket's datetimes, and increment them too |
|
572 | - $success_update_dateimtes = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT |
|
216 | + $this->_old_mer_table = $wpdb->prefix . "events_multi_event_registration_id_group"; |
|
217 | + $this->_new_attendee_cpt_table = $wpdb->posts; |
|
218 | + $this->_new_attendee_meta_table = $wpdb->prefix . "esp_attendee_meta"; |
|
219 | + $this->_new_reg_table = $wpdb->prefix . "esp_registration"; |
|
220 | + $this->_new_transaction_table = $wpdb->prefix . "esp_transaction"; |
|
221 | + $this->_new_payment_table = $wpdb->prefix . "esp_payment"; |
|
222 | + $this->_new_line_table = $wpdb->prefix . "esp_line_item"; |
|
223 | + $this->_new_ticket_table = $wpdb->prefix . "esp_ticket"; |
|
224 | + $this->_new_ticket_datetime_table = $wpdb->prefix . "esp_datetime_ticket"; |
|
225 | + $this->_new_datetime_table = $wpdb->prefix . "esp_datetime"; |
|
226 | + $this->_new_datetime_ticket_table = $wpdb->prefix . "esp_datetime_ticket"; |
|
227 | + $this->_new_price_table = $wpdb->prefix . "esp_price"; |
|
228 | + $this->_new_ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
229 | + parent::__construct(); |
|
230 | + } |
|
231 | + |
|
232 | + protected function _migrate_old_row($old_row) |
|
233 | + { |
|
234 | + // first check if there's already a new attendee with similar characteristics |
|
235 | + $new_att_id = $this->_find_attendee_cpt_matching($old_row); |
|
236 | + if (!$new_att_id) { |
|
237 | + $new_att_id = $this->_insert_new_attendee_cpt($old_row); |
|
238 | + if (!$new_att_id) { |
|
239 | + // if we couldnt even make an attendee, abandon all hope |
|
240 | + return false; |
|
241 | + } |
|
242 | + $new_att_meta_id = $this->_insert_attendee_meta_row($old_row, $new_att_id); |
|
243 | + if ($new_att_meta_id) { |
|
244 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_meta_table, $new_att_meta_id); |
|
245 | + } |
|
246 | + } |
|
247 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id); |
|
248 | + |
|
249 | + $txn_id = $this->_insert_new_transaction($old_row); |
|
250 | + if (!$txn_id) { |
|
251 | + // if we couldnt make the transaction, also abandon all hope |
|
252 | + return false; |
|
253 | + } |
|
254 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_transaction_table, $txn_id); |
|
255 | + $pay_id = $this->_insert_new_payment($old_row, $txn_id); |
|
256 | + if ($pay_id) { |
|
257 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_payment_table, $pay_id); |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + // even if there was no payment, we can go ahead with adding the reg |
|
262 | + $new_regs = $this->_insert_new_registrations($old_row, $new_att_id, $txn_id); |
|
263 | + if ($new_regs) { |
|
264 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_reg_table, $new_regs); |
|
265 | + } |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * Checks if there's already an attendee CPT in the db that has the same |
|
270 | + * first and last name, and email. If so, returns its ID as an int. |
|
271 | + * @global type $wpdb |
|
272 | + * @param array $old_attendee |
|
273 | + * @return int |
|
274 | + */ |
|
275 | + private function _find_attendee_cpt_matching($old_attendee) |
|
276 | + { |
|
277 | + global $wpdb; |
|
278 | + $existing_attendee_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . $this->_new_attendee_cpt_table . " AS cpt INNER JOIN " . $this->_new_attendee_meta_table . " AS meta ON cpt.ID = meta.ATT_ID WHERE meta.ATT_fname = %s AND meta.ATT_lname = %s AND meta.ATT_email = %s LIMIT 1", $old_attendee['fname'], $old_attendee['lname'], $old_attendee['email'])); |
|
279 | + return intval($existing_attendee_id); |
|
280 | + } |
|
281 | + |
|
282 | + private function _insert_new_attendee_cpt($old_attendee) |
|
283 | + { |
|
284 | + global $wpdb; |
|
285 | + $cols_n_values = array( |
|
286 | + 'post_title' => stripslashes($old_attendee['fname'] . " " . $old_attendee['lname']),// ATT_full_name |
|
287 | + 'post_content' => '',// ATT_bio |
|
288 | + 'post_name' => sanitize_title($old_attendee['fname'] . "-" . $old_attendee['lname']),// ATT_slug |
|
289 | + 'post_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created |
|
290 | + 'post_excerpt' => '',// ATT_short_bio |
|
291 | + 'post_modified' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified |
|
292 | + 'post_author' => 0,// ATT_author |
|
293 | + 'post_parent' => 0,// ATT_parent |
|
294 | + 'post_type' => 'espresso_attendees',// post_type |
|
295 | + 'post_status' => 'publish'// status |
|
296 | + ); |
|
297 | + $datatypes = array( |
|
298 | + '%s',// ATT_full_name |
|
299 | + '%s',// ATT_bio |
|
300 | + '%s',// ATT_slug |
|
301 | + '%s',// ATT_created |
|
302 | + '%s',// ATT_short_bio |
|
303 | + '%s',// ATT_modified |
|
304 | + '%d',// ATT_author |
|
305 | + '%d',// ATT_parent |
|
306 | + '%s',// post_type |
|
307 | + '%s',// status |
|
308 | + ); |
|
309 | + $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes); |
|
310 | + if (!$success) { |
|
311 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
|
312 | + return 0; |
|
313 | + } |
|
314 | + $new_id = $wpdb->insert_id; |
|
315 | + return $new_id; |
|
316 | + } |
|
317 | + |
|
318 | + private function _insert_attendee_meta_row($old_attendee, $new_attendee_cpt_id) |
|
319 | + { |
|
320 | + global $wpdb; |
|
321 | + // get the state and country ids from the old row |
|
322 | + try { |
|
323 | + $new_country = $this->get_migration_script()->get_or_create_country(stripslashes($old_attendee['country_id'])); |
|
324 | + $new_country_iso = $new_country['CNT_ISO']; |
|
325 | + } catch (EE_Error $exception) { |
|
326 | + $new_country_iso = $this->get_migration_script()->get_default_country_iso(); |
|
327 | + } |
|
328 | + try { |
|
329 | + $new_state = $this->get_migration_script()->get_or_create_state(stripslashes($old_attendee['state']), $new_country_iso); |
|
330 | + $new_state_id = $new_state['STA_ID']; |
|
331 | + } catch (EE_Error $exception) { |
|
332 | + $new_state_id = 0; |
|
333 | + } |
|
334 | + $cols_n_values = array( |
|
335 | + 'ATT_ID' => $new_attendee_cpt_id, |
|
336 | + 'ATT_fname' => stripslashes($old_attendee['fname']), |
|
337 | + 'ATT_lname' => stripslashes($old_attendee['lname']), |
|
338 | + 'ATT_address' => stripslashes($old_attendee['address']), |
|
339 | + 'ATT_address2' => stripslashes($old_attendee['address2']), |
|
340 | + 'ATT_city' => stripslashes($old_attendee['city']), |
|
341 | + 'STA_ID' => $new_state_id, |
|
342 | + 'CNT_ISO' => $new_country_iso, |
|
343 | + 'ATT_zip' => stripslashes($old_attendee['zip']), |
|
344 | + 'ATT_email' => stripslashes($old_attendee['email']), |
|
345 | + 'ATT_phone' => stripslashes($old_attendee['phone']), |
|
346 | + ); |
|
347 | + $datatypes = array( |
|
348 | + '%d',// ATT_ID |
|
349 | + '%s',// ATT_fname |
|
350 | + '%s',// ATT_lname |
|
351 | + '%s',// ATT_address |
|
352 | + '%s',// ATT_address2 |
|
353 | + '%s',// ATT_city |
|
354 | + '%d',// STA_ID |
|
355 | + '%s',// CNT_ISO |
|
356 | + '%s',// ATT_zip |
|
357 | + '%s',// ATT_email |
|
358 | + '%s',// ATT_phone |
|
359 | + ); |
|
360 | + $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes); |
|
361 | + if (!$success) { |
|
362 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_meta_table, $cols_n_values, $datatypes)); |
|
363 | + return 0; |
|
364 | + } |
|
365 | + $new_id = $wpdb->insert_id; |
|
366 | + return $new_id; |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * Note: we don't necessarily create a new transaction for each attendee row. |
|
371 | + * Only if the old attendee 'is_primary' is true; otherwise we find the old attendee row that |
|
372 | + * 'is_primary' and has the same 'txn_id', then we return ITS new transaction id |
|
373 | + * @global type $wpdb |
|
374 | + * @param type $old_attendee |
|
375 | + * @return int new transaction id |
|
376 | + */ |
|
377 | + private function _insert_new_transaction($old_attendee) |
|
378 | + { |
|
379 | + global $wpdb; |
|
380 | + |
|
381 | + // first: let's check for an existing transaction for this old attendee |
|
382 | + if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn |
|
383 | + $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table); |
|
384 | + } else { // non-primary attendee, so find its primary attendee's transaction |
|
385 | + $primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . $this->_old_table . " WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id'])); |
|
386 | + if (!$primary_attendee_old_id) { |
|
387 | + $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']); |
|
388 | + $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null; |
|
389 | + } |
|
390 | + $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table); |
|
391 | + if (!$txn_id) { |
|
392 | + $this->add_error(sprintf(__("Could not find primary attendee's new transaction. Current attendee is: %s, we think the 3.1 primary attendee for it has id %d, but there's no 4.1 transaction for that primary attendee id.", "event_espresso"), $this->_json_encode($old_attendee), $primary_attendee_old_id)); |
|
393 | + $txn_id = 0; |
|
394 | + } |
|
395 | + } |
|
396 | + // if there isn't yet a transaction row for this, create one |
|
397 | + // (so even if it was a non-primary attendee with no EE3 primary attendee, |
|
398 | + // it ought to have SOME transaction, so we'll make one) |
|
399 | + if (!$txn_id) { |
|
400 | + // maps 3.1 payment stati onto 4.1 transaction stati |
|
401 | + $txn_status_mapping = array( |
|
402 | + 'Completed' => 'TCM', |
|
403 | + 'Pending' => 'TIN', |
|
404 | + 'Payment Declined' => 'TIN', |
|
405 | + 'Incomplete' => 'TIN', |
|
406 | + 'Not Completed' => 'TIN', |
|
407 | + 'Cancelled' => 'TIN', |
|
408 | + 'Declined' => 'TIN' |
|
409 | + ); |
|
410 | + $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN'; |
|
411 | + $cols_n_values = array( |
|
412 | + 'TXN_timestamp' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
413 | + 'TXN_total' => floatval($old_attendee['total_cost']), |
|
414 | + 'TXN_paid' => floatval($old_attendee['amount_pd']), |
|
415 | + 'STS_ID' => $STS_ID, |
|
416 | + 'TXN_hash_salt' => $old_attendee['hashSalt'] |
|
417 | + ); |
|
418 | + $datatypes = array( |
|
419 | + '%s',// TXN_timestamp |
|
420 | + '%f',// TXN_total |
|
421 | + '%f',// TXN_paid |
|
422 | + '%s',// STS_ID |
|
423 | + '%s',// TXN_hash_salt |
|
424 | + ); |
|
425 | + $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes); |
|
426 | + if (!$success) { |
|
427 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_transaction_table, $cols_n_values, $datatypes)); |
|
428 | + return 0; |
|
429 | + } |
|
430 | + $txn_id = $wpdb->insert_id; |
|
431 | + } |
|
432 | + |
|
433 | + return $txn_id; |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * Detects if the MER tables exist |
|
438 | + * @global type $wpdb |
|
439 | + * @return boolean |
|
440 | + */ |
|
441 | + private function _mer_tables_exist() |
|
442 | + { |
|
443 | + if ($this->_mer_tables_exist === null) { |
|
444 | + global $wpdb; |
|
445 | + |
|
446 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$this->_old_mer_table}'") != $this->_old_mer_table) { |
|
447 | + $this->_mer_tables_exist = false; |
|
448 | + } else { |
|
449 | + $this->_mer_tables_exist = true; |
|
450 | + } |
|
451 | + } |
|
452 | + return $this->_mer_tables_exist; |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Gets the 4.1 registration's status given the 3.1 attendee row. We consider |
|
457 | + * whether the event required pre-approval or not,a dn the 4.1 payment status. |
|
458 | + * @global type $wpdb |
|
459 | + * @param type $old_attendee_row |
|
460 | + * @return string |
|
461 | + */ |
|
462 | + private function _get_reg_status_for_old_payment_status($old_attendee_row) |
|
463 | + { |
|
464 | + // need event default reg status and if pre_approval was required |
|
465 | + global $wpdb; |
|
466 | + $event_required_pre_approval = $wpdb->get_var($wpdb->prepare("SELECT require_pre_approval FROM " . $wpdb->prefix . "events_detail WHERE id = %d", $old_attendee_row['event_id'])); |
|
467 | + return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID( |
|
468 | + $old_attendee_row['payment_status'], |
|
469 | + intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve']) |
|
470 | + ); |
|
471 | + } |
|
472 | + |
|
473 | + /** |
|
474 | + * Adds however many rgistrations are indicated by the old attendee's QUANTITY field, |
|
475 | + * and returns an array of their IDs |
|
476 | + * @global type $wpdb |
|
477 | + * @param array $old_attendee |
|
478 | + * @param int $new_attendee_id |
|
479 | + * @param int $new_txn_id |
|
480 | + * @return array of new registratio ids |
|
481 | + */ |
|
482 | + private function _insert_new_registrations($old_attendee, $new_attendee_id, $new_txn_id) |
|
483 | + { |
|
484 | + global $wpdb; |
|
485 | + |
|
486 | + $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee); |
|
487 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . 'events_detail', $old_attendee['event_id'], $wpdb->posts); |
|
488 | + if (!$new_event_id) { |
|
489 | + $this->add_error(sprintf(__("Could not find NEW event CPT ID for old event '%d' on old attendee %s", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee))); |
|
490 | + } |
|
491 | + |
|
492 | + $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id); |
|
493 | + if (!$ticket_id) { |
|
494 | + $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id); |
|
495 | + $this->add_error(sprintf(__('Could not find a ticket for old attendee with id %d for new event %d, so created a new ticket with id %d', 'event_espresso'), $old_attendee['id'], $new_event_id, $ticket_id)); |
|
496 | + } |
|
497 | + $regs_on_this_row = intval($old_attendee['quantity']); |
|
498 | + $new_regs = array(); |
|
499 | + // 4 cases we need to account for: |
|
500 | + // 1 old attendee_details row with a quantity of X (no mer) |
|
501 | + // Y old attendee_details rows with a quantity of 1 (no mer) joined by their common registration_id |
|
502 | + // Y old attendee_details rows with a quantity of x (because of mer) |
|
503 | + // Y old attendee_details rows with a quantity of 1 (because of mer) joined by wp_events_multi_event_registration_id_group |
|
504 | + for ($count = 1; $count <= $regs_on_this_row; $count++) { |
|
505 | + // sum regs on older rows |
|
506 | + $regs_on_this_event_and_txn = $this->_sum_old_attendees_on_old_txn($old_attendee, true); |
|
507 | + $cols_n_values = array( |
|
508 | + 'EVT_ID' => $new_event_id, |
|
509 | + 'ATT_ID' => $new_attendee_id, |
|
510 | + 'TXN_ID' => $new_txn_id, |
|
511 | + 'TKT_ID' => $ticket_id, |
|
512 | + 'STS_ID' => $STS_ID, |
|
513 | + 'REG_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
514 | + 'REG_final_price' => $old_attendee['final_price'], |
|
515 | + 'REG_session' => substr($old_attendee['attendee_session'], 0, 44), |
|
516 | + 'REG_code' => sanitize_key($old_attendee['registration_id']), |
|
517 | + 'REG_url_link' => sanitize_key($old_attendee['registration_id'] . '-' . $count), |
|
518 | + 'REG_count' => $regs_on_this_event_and_txn + $count, |
|
519 | + 'REG_group_size' => $this->_sum_old_attendees_on_old_txn($old_attendee, false), |
|
520 | + 'REG_att_is_going' => true, |
|
521 | + 'REG_deleted' => false |
|
522 | + ); |
|
523 | + $datatypes = array( |
|
524 | + '%d',// EVT_ID |
|
525 | + '%d',// ATT_ID |
|
526 | + '%d',// TXN_ID |
|
527 | + '%d',// TKT_ID |
|
528 | + '%s',// STS_ID |
|
529 | + '%s',// REG_date |
|
530 | + '%f',// REG_final_price |
|
531 | + '%s',// REG_session |
|
532 | + '%s',// REG_code |
|
533 | + '%s',// REG_url_link |
|
534 | + '%d',// REG_count |
|
535 | + '%d',// REG_group_size |
|
536 | + '%d',// REG_att_is_going |
|
537 | + '%d',// REG_deleted |
|
538 | + ); |
|
539 | + $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes); |
|
540 | + if (!$success) { |
|
541 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes)); |
|
542 | + return 0; |
|
543 | + } |
|
544 | + $cols_n_values['REG_ID'] = $wpdb->insert_id; |
|
545 | + $new_regs[] = $wpdb->insert_id; |
|
546 | + } |
|
547 | + $this->_add_regs_to_ticket_and_datetimes($ticket_id, count($new_regs), $STS_ID); |
|
548 | + return $new_regs; |
|
549 | + } |
|
550 | + |
|
551 | + /** |
|
552 | + * Increments the sold values on the ticket and its related datetimes by the amount sold, |
|
553 | + * which should be done directly after adding the rows. Yes this means we're constantly incrementing |
|
554 | + * the sold amounts as we go, and is less efficient than a single big query, |
|
555 | + * but its safer because we KNOW these regs have been added, rather than inferring |
|
556 | + * that they WILL be added (because the attendees stage runs nearly last during |
|
557 | + * the migration script) |
|
558 | + * @param type $new_ticket_id |
|
559 | + * @param type $sold |
|
560 | + * @param type $STS_ID |
|
561 | + * @return boolean whether they were successfully updated or not |
|
562 | + */ |
|
563 | + protected function _add_regs_to_ticket_and_datetimes($new_ticket_id, $quantity_sold, $STS_ID) |
|
564 | + { |
|
565 | + if ($STS_ID != 'RAP') { |
|
566 | + return true; |
|
567 | + } |
|
568 | + global $wpdb; |
|
569 | + $success = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} SET TKT_sold=TKT_sold+%d WHERE TKT_ID=%d", $quantity_sold, $new_ticket_id)); |
|
570 | + if ($success) { |
|
571 | + // get the ticket's datetimes, and increment them too |
|
572 | + $success_update_dateimtes = $wpdb->query($wpdb->prepare("UPDATE {$this->_new_ticket_table} TKT |
|
573 | 573 | INNER JOIN {$this->_new_ticket_datetime_table} as DTK ON TKT.TKT_ID = DTK.TKT_ID |
574 | 574 | INNER JOIN {$this->_new_datetime_table} as DTT ON DTK.DTT_ID = DTT.DTT_ID |
575 | 575 | SET DTT.DTT_sold = DTT.DTT_sold + %d WHERE TKT.TKT_ID = %d", $quantity_sold, $new_ticket_id)); |
576 | - if (!$success_update_dateimtes) { |
|
577 | - $this->add_error(sprintf(__("Could not update datetimes related to ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error)); |
|
578 | - } |
|
579 | - } else { |
|
580 | - $this->add_error(sprintf(__("Could not update ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error)); |
|
581 | - } |
|
582 | - return true; |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * Makes a best guess at which ticket is the one the attendee purchased. |
|
587 | - * Obviously, the old attendee's event_id narrows it down quite a bit; |
|
588 | - * then the old attendee's orig_price and event_time, and price_option can uniquely identify the ticket |
|
589 | - * however, if we don't find an exact match, see if any of those conditions match; |
|
590 | - * and lastly if none of that works, just use the first ticket for the event we find |
|
591 | - * @param array $old_attendee |
|
592 | - */ |
|
593 | - private function _try_to_find_new_ticket_id($old_attendee, $new_event_id) |
|
594 | - { |
|
595 | - global $wpdb; |
|
596 | - $tickets_table = $this->_new_ticket_table; |
|
597 | - $datetime_tickets_table = $this->_new_ticket_datetime_table; |
|
598 | - $datetime_table = $this->_new_datetime_table; |
|
599 | - |
|
600 | - $old_att_price_option = $old_attendee['price_option']; |
|
601 | - $old_att_price = floatval($old_attendee['orig_price']); |
|
602 | - |
|
603 | - $old_att_start_date = $old_attendee['start_date']; |
|
604 | - $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
605 | - $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
606 | - // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
607 | - // the most important condition should be last, as it will be array_shift'ed off last |
|
608 | - $conditions = array( |
|
609 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
610 | - $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match? |
|
611 | - $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match? |
|
612 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
613 | - ); |
|
614 | - $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN |
|
576 | + if (!$success_update_dateimtes) { |
|
577 | + $this->add_error(sprintf(__("Could not update datetimes related to ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error)); |
|
578 | + } |
|
579 | + } else { |
|
580 | + $this->add_error(sprintf(__("Could not update ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error)); |
|
581 | + } |
|
582 | + return true; |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * Makes a best guess at which ticket is the one the attendee purchased. |
|
587 | + * Obviously, the old attendee's event_id narrows it down quite a bit; |
|
588 | + * then the old attendee's orig_price and event_time, and price_option can uniquely identify the ticket |
|
589 | + * however, if we don't find an exact match, see if any of those conditions match; |
|
590 | + * and lastly if none of that works, just use the first ticket for the event we find |
|
591 | + * @param array $old_attendee |
|
592 | + */ |
|
593 | + private function _try_to_find_new_ticket_id($old_attendee, $new_event_id) |
|
594 | + { |
|
595 | + global $wpdb; |
|
596 | + $tickets_table = $this->_new_ticket_table; |
|
597 | + $datetime_tickets_table = $this->_new_ticket_datetime_table; |
|
598 | + $datetime_table = $this->_new_datetime_table; |
|
599 | + |
|
600 | + $old_att_price_option = $old_attendee['price_option']; |
|
601 | + $old_att_price = floatval($old_attendee['orig_price']); |
|
602 | + |
|
603 | + $old_att_start_date = $old_attendee['start_date']; |
|
604 | + $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
605 | + $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
606 | + // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
607 | + // the most important condition should be last, as it will be array_shift'ed off last |
|
608 | + $conditions = array( |
|
609 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
610 | + $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match? |
|
611 | + $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match? |
|
612 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
613 | + ); |
|
614 | + $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN |
|
615 | 615 | $datetime_tickets_table ON $tickets_table.TKT_ID = $datetime_tickets_table.TKT_ID INNER JOIN |
616 | 616 | $datetime_table ON $datetime_tickets_table.DTT_ID = $datetime_table.DTT_ID"; |
617 | - // start running queries, widening search each time by removing a condition |
|
618 | - do { |
|
619 | - $full_query = $select_and_join_part . " WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
620 | - $ticket_id_found = $wpdb->get_var($full_query); |
|
621 | - array_shift($conditions); |
|
622 | - } while (!$ticket_id_found && $conditions); |
|
623 | - return $ticket_id_found; |
|
624 | - } |
|
625 | - |
|
626 | - /** |
|
627 | - * If we couldn't find a 4.1 ticket for a 3.1 attendee row, this function creates one; |
|
628 | - * and it also tries to find a datetime that works, and a inserts a price, and associates |
|
629 | - * the new ticket to that datetime and price. |
|
630 | - * @return int ticket id |
|
631 | - */ |
|
632 | - private function _insert_new_ticket_because_none_found($old_attendee, $new_event_id) |
|
633 | - { |
|
634 | - global $wpdb; |
|
635 | - $old_att_price_option = $old_attendee['price_option']; |
|
636 | - $old_att_price = floatval($old_attendee['orig_price']); |
|
637 | - |
|
638 | - $old_att_start_date = $old_attendee['start_date']; |
|
639 | - $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
640 | - $old_att_start_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
641 | - |
|
642 | - |
|
643 | - // insert new datetime unless we find one |
|
644 | - $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM " . $this->_new_datetime_table . " WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A); |
|
645 | - if (!$datetime_id) { |
|
646 | - $old_att_end_date = $old_attendee['start_date']; |
|
647 | - $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
648 | - $old_att_end_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_end_date $old_att_end_time:00"); |
|
649 | - $wpdb->insert( |
|
650 | - $this->_new_datetime_table, |
|
651 | - array( |
|
652 | - 'EVT_ID' => $new_event_id, |
|
653 | - 'DTT_EVT_start' => $old_att_start_datetime, |
|
654 | - 'DTT_EVT_end' => $old_att_end_datetime, |
|
655 | - 'DTT_deleted' => true |
|
656 | - ), |
|
657 | - array( |
|
658 | - '%d',// EVT_ID |
|
659 | - '%s',// DTT_EVT_start |
|
660 | - '%s',// DTT_EVT_end |
|
661 | - '%d',// DTT_deleted |
|
662 | - ) |
|
663 | - ); |
|
664 | - $datetime_id = $wpdb->insert_id; |
|
665 | - } |
|
666 | - |
|
667 | - // insert new ticket |
|
668 | - $success = $wpdb->insert( |
|
669 | - $wpdb->prefix . 'esp_ticket', |
|
670 | - array( |
|
671 | - 'TKT_name' => $old_att_price_option, |
|
672 | - 'TKT_qty' => -1, |
|
673 | - 'TKT_price' => $old_att_price, |
|
674 | - 'TKT_start_date' => $old_att_start_datetime,// we really have no clue what the time should be, but at least it was available when they attended |
|
675 | - 'TKT_end_date' => $old_att_end_datetime, |
|
676 | - |
|
677 | - ), |
|
678 | - array( |
|
679 | - '%s',// name |
|
680 | - '%d',// qty |
|
681 | - '%d',// price |
|
682 | - '%s',// start_date |
|
683 | - '%s',// end_date |
|
684 | - ) |
|
685 | - ); |
|
686 | - $ticket_id = $wpdb->insert_id; |
|
687 | - // associate the ticket with the datetime we found earlier |
|
688 | - $wpdb->insert( |
|
689 | - $this->_new_datetime_ticket_table, |
|
690 | - array( |
|
691 | - 'DTT_ID' => $datetime_id, |
|
692 | - 'TKT_ID' => $ticket_id |
|
693 | - ), |
|
694 | - array( |
|
695 | - '%d',// DTT_ID |
|
696 | - '%d',// TKT_ID |
|
697 | - ) |
|
698 | - ); |
|
699 | - // insert new price |
|
700 | - $wpdb->insert( |
|
701 | - $this->_new_price_table, |
|
702 | - array( |
|
703 | - 'PRC_amount' => $old_att_price, |
|
704 | - 'PRT_ID' => EE_DMS_4_1_0_prices::price_type_base, |
|
705 | - 'PRC_name' => $old_att_price_option, |
|
706 | - 'PRC_deleted' => true |
|
707 | - ), |
|
708 | - array( |
|
709 | - '%d',// PRC_amount |
|
710 | - '%d',// PRT_ID |
|
711 | - '%s',// PRC_name |
|
712 | - '%d',// PRC_deleted |
|
713 | - ) |
|
714 | - ); |
|
715 | - $price_id = $wpdb->insert_id; |
|
716 | - // associate the price to the ticket |
|
717 | - $wpdb->insert( |
|
718 | - $this->_new_ticket_price_table, |
|
719 | - array( |
|
720 | - 'TKT_ID' => $ticket_id, |
|
721 | - 'PRC_ID' => $price_id |
|
722 | - ), |
|
723 | - array( |
|
724 | - '%d',// TKT_ID |
|
725 | - '%d',// PRC_ID |
|
726 | - ) |
|
727 | - ); |
|
728 | - return $ticket_id; |
|
729 | - } |
|
730 | - |
|
731 | - /** |
|
732 | - * Counts all the registrations on this transaction. If $count_only_older is TRUE then returns the number added SO FAR (ie, |
|
733 | - * only considers attendee rows with an ID less than this one's), but if $count_only_older is FALSe returns ALL |
|
734 | - * @global type $wpdb |
|
735 | - * @param array $old_attendee_row |
|
736 | - * @param boolean $count_only_older true if you want the running count (ie, the total up to this row), and false if you want ALL |
|
737 | - * @return int |
|
738 | - */ |
|
739 | - private function _sum_old_attendees_on_old_txn($old_attendee_row, $count_only_older = false) |
|
740 | - { |
|
741 | - global $wpdb; |
|
742 | - $count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : ''; |
|
743 | - $count = intval($wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM " . $this->_old_table . " WHERE registration_id=%s $count_only_older_sql", $old_attendee_row['registration_id']))); |
|
744 | - |
|
745 | - if ($this->_mer_tables_exist()) { |
|
746 | - // if MER exists, then its a little tricky. |
|
747 | - // when users registered by adding items to the cart, and it was a |
|
748 | - // group registration requiring additional attendee INFO, then the attendee rows |
|
749 | - // DO NOT have the same registration_id (although they probably should have) |
|
750 | - // they are related just like MER attendee rows are related, through the MER group table |
|
751 | - // BUT we want to count all the MER attendee rows for the same registration |
|
752 | - $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee_row['registration_id']); |
|
753 | - |
|
754 | - $count_using_mer_table = $wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM {$this->_old_table} att INNER JOIN {$this->_old_mer_table} mer ON att.registration_id = mer.registration_id WHERE att.event_id=%d AND mer.primary_registration_id = %s $count_only_older_sql", $old_attendee_row['event_id'], $primary_attendee['registration_id'])); |
|
755 | - $count = max($count_using_mer_table, $count); |
|
756 | - } |
|
757 | - return $count; |
|
758 | - } |
|
759 | - |
|
760 | - private function _insert_new_payment($old_attendee, $new_txn_id) |
|
761 | - { |
|
762 | - global $wpdb; |
|
763 | - // only add a payment for primary attendees |
|
764 | - $old_pay_stati_indicating_no_payment = array('Pending', 'Incomplete', 'Not Completed'); |
|
765 | - // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment... |
|
766 | - if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && !in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
|
767 | - $pay_status_mapping = array( |
|
768 | - 'Completed' => 'PAP', |
|
769 | - 'Payment Declined' => 'PDC', |
|
770 | - 'Cancelled' => 'PCN', |
|
771 | - 'Declined' => 'PDC' |
|
772 | - ); |
|
773 | - $by_admin = $old_attendee['payment'] == 'Admin'; |
|
774 | - $STS_ID = isset($pay_status_mapping[ $old_attendee['payment_status'] ]) ? $pay_status_mapping[ $old_attendee['payment_status'] ] : 'PFL';// IE, if we don't recognize the status, assume payment failed |
|
775 | - $cols_n_values = array( |
|
776 | - 'TXN_ID' => $new_txn_id, |
|
777 | - 'STS_ID' => $STS_ID, |
|
778 | - 'PAY_timestamp' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
779 | - 'PAY_method' => 'CART', |
|
780 | - 'PAY_amount' => $old_attendee['amount_pd'], |
|
781 | - 'PAY_gateway' => $old_attendee['txn_type'], |
|
782 | - 'PAY_gateway_response' => '', |
|
783 | - 'PAY_txn_id_chq_nmbr' => substr($old_attendee['txn_id'], 0, 32), |
|
784 | - 'PAY_via_admin' => $by_admin, |
|
785 | - 'PAY_details' => $old_attendee['transaction_details'] |
|
786 | - |
|
787 | - ); |
|
788 | - $datatypes = array( |
|
789 | - '%d',// TXN_Id |
|
790 | - '%s',// STS_ID |
|
791 | - '%s',// PAY_timestamp |
|
792 | - '%s',// PAY_method |
|
793 | - '%f',// PAY_amount |
|
794 | - '%s',// PAY_gateway |
|
795 | - '%s',// PAY_gateway_response |
|
796 | - '%s',// PAY_txn_id_chq_nmbr |
|
797 | - '%d',// PAY_via_admin |
|
798 | - '%s',// PAY_details |
|
799 | - ); |
|
800 | - $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes); |
|
801 | - if (!$success) { |
|
802 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
|
803 | - return 0; |
|
804 | - } |
|
805 | - $new_id = $wpdb->insert_id; |
|
806 | - return $new_id; |
|
807 | - } else { |
|
808 | - return 0; |
|
809 | - } |
|
810 | - } |
|
811 | - |
|
812 | - /** |
|
813 | - * If MER is active, if you want ot fin dthe other registrations on that attendee row |
|
814 | - * @global type $wpdb |
|
815 | - * @param type $old_registration_id |
|
816 | - * @return array |
|
817 | - */ |
|
818 | - private function _find_mer_primary_attendee_using_mer_tables($old_registration_id) |
|
819 | - { |
|
820 | - if (!$this->_mer_tables_exist()) { |
|
821 | - return false; |
|
822 | - } |
|
823 | - global $wpdb; |
|
824 | - $old_att_for_primary_reg = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$this->_old_mer_table} AS mer INNER JOIN {$this->_old_table} AS att ON mer.primary_registration_id = att.registration_id WHERE mer.registration_id=%s LIMIT 1", $old_registration_id), ARRAY_A); |
|
825 | - return $old_att_for_primary_reg; |
|
826 | - } |
|
617 | + // start running queries, widening search each time by removing a condition |
|
618 | + do { |
|
619 | + $full_query = $select_and_join_part . " WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
620 | + $ticket_id_found = $wpdb->get_var($full_query); |
|
621 | + array_shift($conditions); |
|
622 | + } while (!$ticket_id_found && $conditions); |
|
623 | + return $ticket_id_found; |
|
624 | + } |
|
625 | + |
|
626 | + /** |
|
627 | + * If we couldn't find a 4.1 ticket for a 3.1 attendee row, this function creates one; |
|
628 | + * and it also tries to find a datetime that works, and a inserts a price, and associates |
|
629 | + * the new ticket to that datetime and price. |
|
630 | + * @return int ticket id |
|
631 | + */ |
|
632 | + private function _insert_new_ticket_because_none_found($old_attendee, $new_event_id) |
|
633 | + { |
|
634 | + global $wpdb; |
|
635 | + $old_att_price_option = $old_attendee['price_option']; |
|
636 | + $old_att_price = floatval($old_attendee['orig_price']); |
|
637 | + |
|
638 | + $old_att_start_date = $old_attendee['start_date']; |
|
639 | + $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
640 | + $old_att_start_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
641 | + |
|
642 | + |
|
643 | + // insert new datetime unless we find one |
|
644 | + $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM " . $this->_new_datetime_table . " WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A); |
|
645 | + if (!$datetime_id) { |
|
646 | + $old_att_end_date = $old_attendee['start_date']; |
|
647 | + $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
648 | + $old_att_end_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_end_date $old_att_end_time:00"); |
|
649 | + $wpdb->insert( |
|
650 | + $this->_new_datetime_table, |
|
651 | + array( |
|
652 | + 'EVT_ID' => $new_event_id, |
|
653 | + 'DTT_EVT_start' => $old_att_start_datetime, |
|
654 | + 'DTT_EVT_end' => $old_att_end_datetime, |
|
655 | + 'DTT_deleted' => true |
|
656 | + ), |
|
657 | + array( |
|
658 | + '%d',// EVT_ID |
|
659 | + '%s',// DTT_EVT_start |
|
660 | + '%s',// DTT_EVT_end |
|
661 | + '%d',// DTT_deleted |
|
662 | + ) |
|
663 | + ); |
|
664 | + $datetime_id = $wpdb->insert_id; |
|
665 | + } |
|
666 | + |
|
667 | + // insert new ticket |
|
668 | + $success = $wpdb->insert( |
|
669 | + $wpdb->prefix . 'esp_ticket', |
|
670 | + array( |
|
671 | + 'TKT_name' => $old_att_price_option, |
|
672 | + 'TKT_qty' => -1, |
|
673 | + 'TKT_price' => $old_att_price, |
|
674 | + 'TKT_start_date' => $old_att_start_datetime,// we really have no clue what the time should be, but at least it was available when they attended |
|
675 | + 'TKT_end_date' => $old_att_end_datetime, |
|
676 | + |
|
677 | + ), |
|
678 | + array( |
|
679 | + '%s',// name |
|
680 | + '%d',// qty |
|
681 | + '%d',// price |
|
682 | + '%s',// start_date |
|
683 | + '%s',// end_date |
|
684 | + ) |
|
685 | + ); |
|
686 | + $ticket_id = $wpdb->insert_id; |
|
687 | + // associate the ticket with the datetime we found earlier |
|
688 | + $wpdb->insert( |
|
689 | + $this->_new_datetime_ticket_table, |
|
690 | + array( |
|
691 | + 'DTT_ID' => $datetime_id, |
|
692 | + 'TKT_ID' => $ticket_id |
|
693 | + ), |
|
694 | + array( |
|
695 | + '%d',// DTT_ID |
|
696 | + '%d',// TKT_ID |
|
697 | + ) |
|
698 | + ); |
|
699 | + // insert new price |
|
700 | + $wpdb->insert( |
|
701 | + $this->_new_price_table, |
|
702 | + array( |
|
703 | + 'PRC_amount' => $old_att_price, |
|
704 | + 'PRT_ID' => EE_DMS_4_1_0_prices::price_type_base, |
|
705 | + 'PRC_name' => $old_att_price_option, |
|
706 | + 'PRC_deleted' => true |
|
707 | + ), |
|
708 | + array( |
|
709 | + '%d',// PRC_amount |
|
710 | + '%d',// PRT_ID |
|
711 | + '%s',// PRC_name |
|
712 | + '%d',// PRC_deleted |
|
713 | + ) |
|
714 | + ); |
|
715 | + $price_id = $wpdb->insert_id; |
|
716 | + // associate the price to the ticket |
|
717 | + $wpdb->insert( |
|
718 | + $this->_new_ticket_price_table, |
|
719 | + array( |
|
720 | + 'TKT_ID' => $ticket_id, |
|
721 | + 'PRC_ID' => $price_id |
|
722 | + ), |
|
723 | + array( |
|
724 | + '%d',// TKT_ID |
|
725 | + '%d',// PRC_ID |
|
726 | + ) |
|
727 | + ); |
|
728 | + return $ticket_id; |
|
729 | + } |
|
730 | + |
|
731 | + /** |
|
732 | + * Counts all the registrations on this transaction. If $count_only_older is TRUE then returns the number added SO FAR (ie, |
|
733 | + * only considers attendee rows with an ID less than this one's), but if $count_only_older is FALSe returns ALL |
|
734 | + * @global type $wpdb |
|
735 | + * @param array $old_attendee_row |
|
736 | + * @param boolean $count_only_older true if you want the running count (ie, the total up to this row), and false if you want ALL |
|
737 | + * @return int |
|
738 | + */ |
|
739 | + private function _sum_old_attendees_on_old_txn($old_attendee_row, $count_only_older = false) |
|
740 | + { |
|
741 | + global $wpdb; |
|
742 | + $count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : ''; |
|
743 | + $count = intval($wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM " . $this->_old_table . " WHERE registration_id=%s $count_only_older_sql", $old_attendee_row['registration_id']))); |
|
744 | + |
|
745 | + if ($this->_mer_tables_exist()) { |
|
746 | + // if MER exists, then its a little tricky. |
|
747 | + // when users registered by adding items to the cart, and it was a |
|
748 | + // group registration requiring additional attendee INFO, then the attendee rows |
|
749 | + // DO NOT have the same registration_id (although they probably should have) |
|
750 | + // they are related just like MER attendee rows are related, through the MER group table |
|
751 | + // BUT we want to count all the MER attendee rows for the same registration |
|
752 | + $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee_row['registration_id']); |
|
753 | + |
|
754 | + $count_using_mer_table = $wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM {$this->_old_table} att INNER JOIN {$this->_old_mer_table} mer ON att.registration_id = mer.registration_id WHERE att.event_id=%d AND mer.primary_registration_id = %s $count_only_older_sql", $old_attendee_row['event_id'], $primary_attendee['registration_id'])); |
|
755 | + $count = max($count_using_mer_table, $count); |
|
756 | + } |
|
757 | + return $count; |
|
758 | + } |
|
759 | + |
|
760 | + private function _insert_new_payment($old_attendee, $new_txn_id) |
|
761 | + { |
|
762 | + global $wpdb; |
|
763 | + // only add a payment for primary attendees |
|
764 | + $old_pay_stati_indicating_no_payment = array('Pending', 'Incomplete', 'Not Completed'); |
|
765 | + // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment... |
|
766 | + if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && !in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
|
767 | + $pay_status_mapping = array( |
|
768 | + 'Completed' => 'PAP', |
|
769 | + 'Payment Declined' => 'PDC', |
|
770 | + 'Cancelled' => 'PCN', |
|
771 | + 'Declined' => 'PDC' |
|
772 | + ); |
|
773 | + $by_admin = $old_attendee['payment'] == 'Admin'; |
|
774 | + $STS_ID = isset($pay_status_mapping[ $old_attendee['payment_status'] ]) ? $pay_status_mapping[ $old_attendee['payment_status'] ] : 'PFL';// IE, if we don't recognize the status, assume payment failed |
|
775 | + $cols_n_values = array( |
|
776 | + 'TXN_ID' => $new_txn_id, |
|
777 | + 'STS_ID' => $STS_ID, |
|
778 | + 'PAY_timestamp' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
|
779 | + 'PAY_method' => 'CART', |
|
780 | + 'PAY_amount' => $old_attendee['amount_pd'], |
|
781 | + 'PAY_gateway' => $old_attendee['txn_type'], |
|
782 | + 'PAY_gateway_response' => '', |
|
783 | + 'PAY_txn_id_chq_nmbr' => substr($old_attendee['txn_id'], 0, 32), |
|
784 | + 'PAY_via_admin' => $by_admin, |
|
785 | + 'PAY_details' => $old_attendee['transaction_details'] |
|
786 | + |
|
787 | + ); |
|
788 | + $datatypes = array( |
|
789 | + '%d',// TXN_Id |
|
790 | + '%s',// STS_ID |
|
791 | + '%s',// PAY_timestamp |
|
792 | + '%s',// PAY_method |
|
793 | + '%f',// PAY_amount |
|
794 | + '%s',// PAY_gateway |
|
795 | + '%s',// PAY_gateway_response |
|
796 | + '%s',// PAY_txn_id_chq_nmbr |
|
797 | + '%d',// PAY_via_admin |
|
798 | + '%s',// PAY_details |
|
799 | + ); |
|
800 | + $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes); |
|
801 | + if (!$success) { |
|
802 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
|
803 | + return 0; |
|
804 | + } |
|
805 | + $new_id = $wpdb->insert_id; |
|
806 | + return $new_id; |
|
807 | + } else { |
|
808 | + return 0; |
|
809 | + } |
|
810 | + } |
|
811 | + |
|
812 | + /** |
|
813 | + * If MER is active, if you want ot fin dthe other registrations on that attendee row |
|
814 | + * @global type $wpdb |
|
815 | + * @param type $old_registration_id |
|
816 | + * @return array |
|
817 | + */ |
|
818 | + private function _find_mer_primary_attendee_using_mer_tables($old_registration_id) |
|
819 | + { |
|
820 | + if (!$this->_mer_tables_exist()) { |
|
821 | + return false; |
|
822 | + } |
|
823 | + global $wpdb; |
|
824 | + $old_att_for_primary_reg = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$this->_old_mer_table} AS mer INNER JOIN {$this->_old_table} AS att ON mer.primary_registration_id = att.registration_id WHERE mer.registration_id=%s LIMIT 1", $old_registration_id), ARRAY_A); |
|
825 | + return $old_att_for_primary_reg; |
|
826 | + } |
|
827 | 827 | } |
@@ -206,26 +206,26 @@ discard block |
||
206 | 206 | { |
207 | 207 | global $wpdb; |
208 | 208 | $this->_pretty_name = __("Attendees", "event_espresso"); |
209 | - $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
209 | + $this->_old_table = $wpdb->prefix."events_attendee"; |
|
210 | 210 | // Only select the event status column from the event table. |
211 | 211 | $this->select_expression = 'att.*, e.event_status'; |
212 | 212 | // Only select attendees for events that aren't deleted. |
213 | 213 | $this->_extra_where_sql = 'AS att |
214 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
|
214 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id |
|
215 | 215 | WHERE e.event_status!="D"'; |
216 | - $this->_old_mer_table = $wpdb->prefix . "events_multi_event_registration_id_group"; |
|
216 | + $this->_old_mer_table = $wpdb->prefix."events_multi_event_registration_id_group"; |
|
217 | 217 | $this->_new_attendee_cpt_table = $wpdb->posts; |
218 | - $this->_new_attendee_meta_table = $wpdb->prefix . "esp_attendee_meta"; |
|
219 | - $this->_new_reg_table = $wpdb->prefix . "esp_registration"; |
|
220 | - $this->_new_transaction_table = $wpdb->prefix . "esp_transaction"; |
|
221 | - $this->_new_payment_table = $wpdb->prefix . "esp_payment"; |
|
222 | - $this->_new_line_table = $wpdb->prefix . "esp_line_item"; |
|
223 | - $this->_new_ticket_table = $wpdb->prefix . "esp_ticket"; |
|
224 | - $this->_new_ticket_datetime_table = $wpdb->prefix . "esp_datetime_ticket"; |
|
225 | - $this->_new_datetime_table = $wpdb->prefix . "esp_datetime"; |
|
226 | - $this->_new_datetime_ticket_table = $wpdb->prefix . "esp_datetime_ticket"; |
|
227 | - $this->_new_price_table = $wpdb->prefix . "esp_price"; |
|
228 | - $this->_new_ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
218 | + $this->_new_attendee_meta_table = $wpdb->prefix."esp_attendee_meta"; |
|
219 | + $this->_new_reg_table = $wpdb->prefix."esp_registration"; |
|
220 | + $this->_new_transaction_table = $wpdb->prefix."esp_transaction"; |
|
221 | + $this->_new_payment_table = $wpdb->prefix."esp_payment"; |
|
222 | + $this->_new_line_table = $wpdb->prefix."esp_line_item"; |
|
223 | + $this->_new_ticket_table = $wpdb->prefix."esp_ticket"; |
|
224 | + $this->_new_ticket_datetime_table = $wpdb->prefix."esp_datetime_ticket"; |
|
225 | + $this->_new_datetime_table = $wpdb->prefix."esp_datetime"; |
|
226 | + $this->_new_datetime_ticket_table = $wpdb->prefix."esp_datetime_ticket"; |
|
227 | + $this->_new_price_table = $wpdb->prefix."esp_price"; |
|
228 | + $this->_new_ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
229 | 229 | parent::__construct(); |
230 | 230 | } |
231 | 231 | |
@@ -233,9 +233,9 @@ discard block |
||
233 | 233 | { |
234 | 234 | // first check if there's already a new attendee with similar characteristics |
235 | 235 | $new_att_id = $this->_find_attendee_cpt_matching($old_row); |
236 | - if (!$new_att_id) { |
|
236 | + if ( ! $new_att_id) { |
|
237 | 237 | $new_att_id = $this->_insert_new_attendee_cpt($old_row); |
238 | - if (!$new_att_id) { |
|
238 | + if ( ! $new_att_id) { |
|
239 | 239 | // if we couldnt even make an attendee, abandon all hope |
240 | 240 | return false; |
241 | 241 | } |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | $this->get_migration_script()->set_mapping($this->_old_table, $old_row['id'], $this->_new_attendee_cpt_table, $new_att_id); |
248 | 248 | |
249 | 249 | $txn_id = $this->_insert_new_transaction($old_row); |
250 | - if (!$txn_id) { |
|
250 | + if ( ! $txn_id) { |
|
251 | 251 | // if we couldnt make the transaction, also abandon all hope |
252 | 252 | return false; |
253 | 253 | } |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | private function _find_attendee_cpt_matching($old_attendee) |
276 | 276 | { |
277 | 277 | global $wpdb; |
278 | - $existing_attendee_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . $this->_new_attendee_cpt_table . " AS cpt INNER JOIN " . $this->_new_attendee_meta_table . " AS meta ON cpt.ID = meta.ATT_ID WHERE meta.ATT_fname = %s AND meta.ATT_lname = %s AND meta.ATT_email = %s LIMIT 1", $old_attendee['fname'], $old_attendee['lname'], $old_attendee['email'])); |
|
278 | + $existing_attendee_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_new_attendee_cpt_table." AS cpt INNER JOIN ".$this->_new_attendee_meta_table." AS meta ON cpt.ID = meta.ATT_ID WHERE meta.ATT_fname = %s AND meta.ATT_lname = %s AND meta.ATT_email = %s LIMIT 1", $old_attendee['fname'], $old_attendee['lname'], $old_attendee['email'])); |
|
279 | 279 | return intval($existing_attendee_id); |
280 | 280 | } |
281 | 281 | |
@@ -283,31 +283,31 @@ discard block |
||
283 | 283 | { |
284 | 284 | global $wpdb; |
285 | 285 | $cols_n_values = array( |
286 | - 'post_title' => stripslashes($old_attendee['fname'] . " " . $old_attendee['lname']),// ATT_full_name |
|
287 | - 'post_content' => '',// ATT_bio |
|
288 | - 'post_name' => sanitize_title($old_attendee['fname'] . "-" . $old_attendee['lname']),// ATT_slug |
|
289 | - 'post_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_created |
|
290 | - 'post_excerpt' => '',// ATT_short_bio |
|
291 | - 'post_modified' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']),// ATT_modified |
|
292 | - 'post_author' => 0,// ATT_author |
|
293 | - 'post_parent' => 0,// ATT_parent |
|
294 | - 'post_type' => 'espresso_attendees',// post_type |
|
286 | + 'post_title' => stripslashes($old_attendee['fname']." ".$old_attendee['lname']), // ATT_full_name |
|
287 | + 'post_content' => '', // ATT_bio |
|
288 | + 'post_name' => sanitize_title($old_attendee['fname']."-".$old_attendee['lname']), // ATT_slug |
|
289 | + 'post_date' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), // ATT_created |
|
290 | + 'post_excerpt' => '', // ATT_short_bio |
|
291 | + 'post_modified' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), // ATT_modified |
|
292 | + 'post_author' => 0, // ATT_author |
|
293 | + 'post_parent' => 0, // ATT_parent |
|
294 | + 'post_type' => 'espresso_attendees', // post_type |
|
295 | 295 | 'post_status' => 'publish'// status |
296 | 296 | ); |
297 | 297 | $datatypes = array( |
298 | - '%s',// ATT_full_name |
|
299 | - '%s',// ATT_bio |
|
300 | - '%s',// ATT_slug |
|
301 | - '%s',// ATT_created |
|
302 | - '%s',// ATT_short_bio |
|
303 | - '%s',// ATT_modified |
|
304 | - '%d',// ATT_author |
|
305 | - '%d',// ATT_parent |
|
306 | - '%s',// post_type |
|
307 | - '%s',// status |
|
298 | + '%s', // ATT_full_name |
|
299 | + '%s', // ATT_bio |
|
300 | + '%s', // ATT_slug |
|
301 | + '%s', // ATT_created |
|
302 | + '%s', // ATT_short_bio |
|
303 | + '%s', // ATT_modified |
|
304 | + '%d', // ATT_author |
|
305 | + '%d', // ATT_parent |
|
306 | + '%s', // post_type |
|
307 | + '%s', // status |
|
308 | 308 | ); |
309 | 309 | $success = $wpdb->insert($this->_new_attendee_cpt_table, $cols_n_values, $datatypes); |
310 | - if (!$success) { |
|
310 | + if ( ! $success) { |
|
311 | 311 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
312 | 312 | return 0; |
313 | 313 | } |
@@ -345,20 +345,20 @@ discard block |
||
345 | 345 | 'ATT_phone' => stripslashes($old_attendee['phone']), |
346 | 346 | ); |
347 | 347 | $datatypes = array( |
348 | - '%d',// ATT_ID |
|
349 | - '%s',// ATT_fname |
|
350 | - '%s',// ATT_lname |
|
351 | - '%s',// ATT_address |
|
352 | - '%s',// ATT_address2 |
|
353 | - '%s',// ATT_city |
|
354 | - '%d',// STA_ID |
|
355 | - '%s',// CNT_ISO |
|
356 | - '%s',// ATT_zip |
|
357 | - '%s',// ATT_email |
|
358 | - '%s',// ATT_phone |
|
348 | + '%d', // ATT_ID |
|
349 | + '%s', // ATT_fname |
|
350 | + '%s', // ATT_lname |
|
351 | + '%s', // ATT_address |
|
352 | + '%s', // ATT_address2 |
|
353 | + '%s', // ATT_city |
|
354 | + '%d', // STA_ID |
|
355 | + '%s', // CNT_ISO |
|
356 | + '%s', // ATT_zip |
|
357 | + '%s', // ATT_email |
|
358 | + '%s', // ATT_phone |
|
359 | 359 | ); |
360 | 360 | $success = $wpdb->insert($this->_new_attendee_meta_table, $cols_n_values, $datatypes); |
361 | - if (!$success) { |
|
361 | + if ( ! $success) { |
|
362 | 362 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_meta_table, $cols_n_values, $datatypes)); |
363 | 363 | return 0; |
364 | 364 | } |
@@ -382,13 +382,13 @@ discard block |
||
382 | 382 | if (intval($old_attendee['is_primary'])) {// primary attendee, so create txn |
383 | 383 | $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($old_attendee['id']), $this->_new_transaction_table); |
384 | 384 | } else { // non-primary attendee, so find its primary attendee's transaction |
385 | - $primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . $this->_old_table . " WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id'])); |
|
386 | - if (!$primary_attendee_old_id) { |
|
385 | + $primary_attendee_old_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".$this->_old_table." WHERE is_primary=1 and registration_id=%s", $old_attendee['registration_id'])); |
|
386 | + if ( ! $primary_attendee_old_id) { |
|
387 | 387 | $primary_attendee = $this->_find_mer_primary_attendee_using_mer_tables($old_attendee['registration_id']); |
388 | 388 | $primary_attendee_old_id = is_array($primary_attendee) ? $primary_attendee['id'] : null; |
389 | 389 | } |
390 | 390 | $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, intval($primary_attendee_old_id), $this->_new_transaction_table); |
391 | - if (!$txn_id) { |
|
391 | + if ( ! $txn_id) { |
|
392 | 392 | $this->add_error(sprintf(__("Could not find primary attendee's new transaction. Current attendee is: %s, we think the 3.1 primary attendee for it has id %d, but there's no 4.1 transaction for that primary attendee id.", "event_espresso"), $this->_json_encode($old_attendee), $primary_attendee_old_id)); |
393 | 393 | $txn_id = 0; |
394 | 394 | } |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | // if there isn't yet a transaction row for this, create one |
397 | 397 | // (so even if it was a non-primary attendee with no EE3 primary attendee, |
398 | 398 | // it ought to have SOME transaction, so we'll make one) |
399 | - if (!$txn_id) { |
|
399 | + if ( ! $txn_id) { |
|
400 | 400 | // maps 3.1 payment stati onto 4.1 transaction stati |
401 | 401 | $txn_status_mapping = array( |
402 | 402 | 'Completed' => 'TCM', |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | 'Cancelled' => 'TIN', |
408 | 408 | 'Declined' => 'TIN' |
409 | 409 | ); |
410 | - $STS_ID = isset($txn_status_mapping[ $old_attendee['payment_status'] ]) ? $txn_status_mapping[ $old_attendee['payment_status'] ] : 'TIN'; |
|
410 | + $STS_ID = isset($txn_status_mapping[$old_attendee['payment_status']]) ? $txn_status_mapping[$old_attendee['payment_status']] : 'TIN'; |
|
411 | 411 | $cols_n_values = array( |
412 | 412 | 'TXN_timestamp' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, $old_attendee['date']), |
413 | 413 | 'TXN_total' => floatval($old_attendee['total_cost']), |
@@ -416,14 +416,14 @@ discard block |
||
416 | 416 | 'TXN_hash_salt' => $old_attendee['hashSalt'] |
417 | 417 | ); |
418 | 418 | $datatypes = array( |
419 | - '%s',// TXN_timestamp |
|
420 | - '%f',// TXN_total |
|
421 | - '%f',// TXN_paid |
|
422 | - '%s',// STS_ID |
|
423 | - '%s',// TXN_hash_salt |
|
419 | + '%s', // TXN_timestamp |
|
420 | + '%f', // TXN_total |
|
421 | + '%f', // TXN_paid |
|
422 | + '%s', // STS_ID |
|
423 | + '%s', // TXN_hash_salt |
|
424 | 424 | ); |
425 | 425 | $success = $wpdb->insert($this->_new_transaction_table, $cols_n_values, $datatypes); |
426 | - if (!$success) { |
|
426 | + if ( ! $success) { |
|
427 | 427 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_transaction_table, $cols_n_values, $datatypes)); |
428 | 428 | return 0; |
429 | 429 | } |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | { |
464 | 464 | // need event default reg status and if pre_approval was required |
465 | 465 | global $wpdb; |
466 | - $event_required_pre_approval = $wpdb->get_var($wpdb->prepare("SELECT require_pre_approval FROM " . $wpdb->prefix . "events_detail WHERE id = %d", $old_attendee_row['event_id'])); |
|
466 | + $event_required_pre_approval = $wpdb->get_var($wpdb->prepare("SELECT require_pre_approval FROM ".$wpdb->prefix."events_detail WHERE id = %d", $old_attendee_row['event_id'])); |
|
467 | 467 | return $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID( |
468 | 468 | $old_attendee_row['payment_status'], |
469 | 469 | intval($event_required_pre_approval) && intval($old_attendee_row['pre_approve']) |
@@ -484,13 +484,13 @@ discard block |
||
484 | 484 | global $wpdb; |
485 | 485 | |
486 | 486 | $STS_ID = $this->_get_reg_status_for_old_payment_status($old_attendee); |
487 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . 'events_detail', $old_attendee['event_id'], $wpdb->posts); |
|
488 | - if (!$new_event_id) { |
|
487 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix.'events_detail', $old_attendee['event_id'], $wpdb->posts); |
|
488 | + if ( ! $new_event_id) { |
|
489 | 489 | $this->add_error(sprintf(__("Could not find NEW event CPT ID for old event '%d' on old attendee %s", "event_espresso"), $old_attendee['event_id'], $this->_json_encode($old_attendee))); |
490 | 490 | } |
491 | 491 | |
492 | 492 | $ticket_id = $this->_try_to_find_new_ticket_id($old_attendee, $new_event_id); |
493 | - if (!$ticket_id) { |
|
493 | + if ( ! $ticket_id) { |
|
494 | 494 | $ticket_id = $this->_insert_new_ticket_because_none_found($old_attendee, $new_event_id); |
495 | 495 | $this->add_error(sprintf(__('Could not find a ticket for old attendee with id %d for new event %d, so created a new ticket with id %d', 'event_espresso'), $old_attendee['id'], $new_event_id, $ticket_id)); |
496 | 496 | } |
@@ -514,30 +514,30 @@ discard block |
||
514 | 514 | 'REG_final_price' => $old_attendee['final_price'], |
515 | 515 | 'REG_session' => substr($old_attendee['attendee_session'], 0, 44), |
516 | 516 | 'REG_code' => sanitize_key($old_attendee['registration_id']), |
517 | - 'REG_url_link' => sanitize_key($old_attendee['registration_id'] . '-' . $count), |
|
517 | + 'REG_url_link' => sanitize_key($old_attendee['registration_id'].'-'.$count), |
|
518 | 518 | 'REG_count' => $regs_on_this_event_and_txn + $count, |
519 | 519 | 'REG_group_size' => $this->_sum_old_attendees_on_old_txn($old_attendee, false), |
520 | 520 | 'REG_att_is_going' => true, |
521 | 521 | 'REG_deleted' => false |
522 | 522 | ); |
523 | 523 | $datatypes = array( |
524 | - '%d',// EVT_ID |
|
525 | - '%d',// ATT_ID |
|
526 | - '%d',// TXN_ID |
|
527 | - '%d',// TKT_ID |
|
528 | - '%s',// STS_ID |
|
529 | - '%s',// REG_date |
|
530 | - '%f',// REG_final_price |
|
531 | - '%s',// REG_session |
|
532 | - '%s',// REG_code |
|
533 | - '%s',// REG_url_link |
|
534 | - '%d',// REG_count |
|
535 | - '%d',// REG_group_size |
|
536 | - '%d',// REG_att_is_going |
|
537 | - '%d',// REG_deleted |
|
524 | + '%d', // EVT_ID |
|
525 | + '%d', // ATT_ID |
|
526 | + '%d', // TXN_ID |
|
527 | + '%d', // TKT_ID |
|
528 | + '%s', // STS_ID |
|
529 | + '%s', // REG_date |
|
530 | + '%f', // REG_final_price |
|
531 | + '%s', // REG_session |
|
532 | + '%s', // REG_code |
|
533 | + '%s', // REG_url_link |
|
534 | + '%d', // REG_count |
|
535 | + '%d', // REG_group_size |
|
536 | + '%d', // REG_att_is_going |
|
537 | + '%d', // REG_deleted |
|
538 | 538 | ); |
539 | 539 | $success = $wpdb->insert($this->_new_reg_table, $cols_n_values, $datatypes); |
540 | - if (!$success) { |
|
540 | + if ( ! $success) { |
|
541 | 541 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_reg_table, $cols_n_values, $datatypes)); |
542 | 542 | return 0; |
543 | 543 | } |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | INNER JOIN {$this->_new_ticket_datetime_table} as DTK ON TKT.TKT_ID = DTK.TKT_ID |
574 | 574 | INNER JOIN {$this->_new_datetime_table} as DTT ON DTK.DTT_ID = DTT.DTT_ID |
575 | 575 | SET DTT.DTT_sold = DTT.DTT_sold + %d WHERE TKT.TKT_ID = %d", $quantity_sold, $new_ticket_id)); |
576 | - if (!$success_update_dateimtes) { |
|
576 | + if ( ! $success_update_dateimtes) { |
|
577 | 577 | $this->add_error(sprintf(__("Could not update datetimes related to ticket with ID %d's TKT_sold by %d because %s", "event_espresso"), $new_ticket_id, $quantity_sold, $wpdb->last_error)); |
578 | 578 | } |
579 | 579 | } else { |
@@ -606,20 +606,20 @@ discard block |
||
606 | 606 | // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
607 | 607 | // the most important condition should be last, as it will be array_shift'ed off last |
608 | 608 | $conditions = array( |
609 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
610 | - $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price),// prices match? |
|
611 | - $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option),// names match? |
|
612 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
609 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match? |
|
610 | + $wpdb->prepare("$tickets_table.TKT_price = %f", $old_att_price), // prices match? |
|
611 | + $wpdb->prepare("$tickets_table.TKT_name = %s", $old_att_price_option), // names match? |
|
612 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match? |
|
613 | 613 | ); |
614 | 614 | $select_and_join_part = "SELECT $tickets_table.TKT_ID FROM $tickets_table INNER JOIN |
615 | 615 | $datetime_tickets_table ON $tickets_table.TKT_ID = $datetime_tickets_table.TKT_ID INNER JOIN |
616 | 616 | $datetime_table ON $datetime_tickets_table.DTT_ID = $datetime_table.DTT_ID"; |
617 | 617 | // start running queries, widening search each time by removing a condition |
618 | 618 | do { |
619 | - $full_query = $select_and_join_part . " WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
619 | + $full_query = $select_and_join_part." WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
620 | 620 | $ticket_id_found = $wpdb->get_var($full_query); |
621 | 621 | array_shift($conditions); |
622 | - } while (!$ticket_id_found && $conditions); |
|
622 | + }while ( ! $ticket_id_found && $conditions); |
|
623 | 623 | return $ticket_id_found; |
624 | 624 | } |
625 | 625 | |
@@ -641,8 +641,8 @@ discard block |
||
641 | 641 | |
642 | 642 | |
643 | 643 | // insert new datetime unless we find one |
644 | - $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM " . $this->_new_datetime_table . " WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A); |
|
645 | - if (!$datetime_id) { |
|
644 | + $datetime_id = $wpdb->get_var($wpdb->prepare("SELECT DTT_ID FROM ".$this->_new_datetime_table." WHERE DTT_EVT_start=%s AND EVT_ID=%d LIMIT 1", $old_att_start_datetime, $new_event_id), ARRAY_A); |
|
645 | + if ( ! $datetime_id) { |
|
646 | 646 | $old_att_end_date = $old_attendee['start_date']; |
647 | 647 | $old_att_end_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
648 | 648 | $old_att_end_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_end_date $old_att_end_time:00"); |
@@ -655,10 +655,10 @@ discard block |
||
655 | 655 | 'DTT_deleted' => true |
656 | 656 | ), |
657 | 657 | array( |
658 | - '%d',// EVT_ID |
|
659 | - '%s',// DTT_EVT_start |
|
660 | - '%s',// DTT_EVT_end |
|
661 | - '%d',// DTT_deleted |
|
658 | + '%d', // EVT_ID |
|
659 | + '%s', // DTT_EVT_start |
|
660 | + '%s', // DTT_EVT_end |
|
661 | + '%d', // DTT_deleted |
|
662 | 662 | ) |
663 | 663 | ); |
664 | 664 | $datetime_id = $wpdb->insert_id; |
@@ -666,21 +666,21 @@ discard block |
||
666 | 666 | |
667 | 667 | // insert new ticket |
668 | 668 | $success = $wpdb->insert( |
669 | - $wpdb->prefix . 'esp_ticket', |
|
669 | + $wpdb->prefix.'esp_ticket', |
|
670 | 670 | array( |
671 | 671 | 'TKT_name' => $old_att_price_option, |
672 | 672 | 'TKT_qty' => -1, |
673 | 673 | 'TKT_price' => $old_att_price, |
674 | - 'TKT_start_date' => $old_att_start_datetime,// we really have no clue what the time should be, but at least it was available when they attended |
|
674 | + 'TKT_start_date' => $old_att_start_datetime, // we really have no clue what the time should be, but at least it was available when they attended |
|
675 | 675 | 'TKT_end_date' => $old_att_end_datetime, |
676 | 676 | |
677 | 677 | ), |
678 | 678 | array( |
679 | - '%s',// name |
|
680 | - '%d',// qty |
|
681 | - '%d',// price |
|
682 | - '%s',// start_date |
|
683 | - '%s',// end_date |
|
679 | + '%s', // name |
|
680 | + '%d', // qty |
|
681 | + '%d', // price |
|
682 | + '%s', // start_date |
|
683 | + '%s', // end_date |
|
684 | 684 | ) |
685 | 685 | ); |
686 | 686 | $ticket_id = $wpdb->insert_id; |
@@ -692,8 +692,8 @@ discard block |
||
692 | 692 | 'TKT_ID' => $ticket_id |
693 | 693 | ), |
694 | 694 | array( |
695 | - '%d',// DTT_ID |
|
696 | - '%d',// TKT_ID |
|
695 | + '%d', // DTT_ID |
|
696 | + '%d', // TKT_ID |
|
697 | 697 | ) |
698 | 698 | ); |
699 | 699 | // insert new price |
@@ -706,10 +706,10 @@ discard block |
||
706 | 706 | 'PRC_deleted' => true |
707 | 707 | ), |
708 | 708 | array( |
709 | - '%d',// PRC_amount |
|
710 | - '%d',// PRT_ID |
|
711 | - '%s',// PRC_name |
|
712 | - '%d',// PRC_deleted |
|
709 | + '%d', // PRC_amount |
|
710 | + '%d', // PRT_ID |
|
711 | + '%s', // PRC_name |
|
712 | + '%d', // PRC_deleted |
|
713 | 713 | ) |
714 | 714 | ); |
715 | 715 | $price_id = $wpdb->insert_id; |
@@ -721,8 +721,8 @@ discard block |
||
721 | 721 | 'PRC_ID' => $price_id |
722 | 722 | ), |
723 | 723 | array( |
724 | - '%d',// TKT_ID |
|
725 | - '%d',// PRC_ID |
|
724 | + '%d', // TKT_ID |
|
725 | + '%d', // PRC_ID |
|
726 | 726 | ) |
727 | 727 | ); |
728 | 728 | return $ticket_id; |
@@ -740,7 +740,7 @@ discard block |
||
740 | 740 | { |
741 | 741 | global $wpdb; |
742 | 742 | $count_only_older_sql = $count_only_older ? $wpdb->prepare(" AND id<%d", $old_attendee_row['id']) : ''; |
743 | - $count = intval($wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM " . $this->_old_table . " WHERE registration_id=%s $count_only_older_sql", $old_attendee_row['registration_id']))); |
|
743 | + $count = intval($wpdb->get_var($wpdb->prepare("SELECT SUM(quantity) FROM ".$this->_old_table." WHERE registration_id=%s $count_only_older_sql", $old_attendee_row['registration_id']))); |
|
744 | 744 | |
745 | 745 | if ($this->_mer_tables_exist()) { |
746 | 746 | // if MER exists, then its a little tricky. |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | // only add a payment for primary attendees |
764 | 764 | $old_pay_stati_indicating_no_payment = array('Pending', 'Incomplete', 'Not Completed'); |
765 | 765 | // if this is for a primary 3.1 attendee which WASN'T free and has a completed, cancelled, or declined payment... |
766 | - if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && !in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
|
766 | + if (intval($old_attendee['is_primary']) && floatval($old_attendee['total_cost']) && ! in_array($old_attendee['payment_status'], $old_pay_stati_indicating_no_payment)) { |
|
767 | 767 | $pay_status_mapping = array( |
768 | 768 | 'Completed' => 'PAP', |
769 | 769 | 'Payment Declined' => 'PDC', |
@@ -771,7 +771,7 @@ discard block |
||
771 | 771 | 'Declined' => 'PDC' |
772 | 772 | ); |
773 | 773 | $by_admin = $old_attendee['payment'] == 'Admin'; |
774 | - $STS_ID = isset($pay_status_mapping[ $old_attendee['payment_status'] ]) ? $pay_status_mapping[ $old_attendee['payment_status'] ] : 'PFL';// IE, if we don't recognize the status, assume payment failed |
|
774 | + $STS_ID = isset($pay_status_mapping[$old_attendee['payment_status']]) ? $pay_status_mapping[$old_attendee['payment_status']] : 'PFL'; // IE, if we don't recognize the status, assume payment failed |
|
775 | 775 | $cols_n_values = array( |
776 | 776 | 'TXN_ID' => $new_txn_id, |
777 | 777 | 'STS_ID' => $STS_ID, |
@@ -786,19 +786,19 @@ discard block |
||
786 | 786 | |
787 | 787 | ); |
788 | 788 | $datatypes = array( |
789 | - '%d',// TXN_Id |
|
790 | - '%s',// STS_ID |
|
791 | - '%s',// PAY_timestamp |
|
792 | - '%s',// PAY_method |
|
793 | - '%f',// PAY_amount |
|
794 | - '%s',// PAY_gateway |
|
795 | - '%s',// PAY_gateway_response |
|
796 | - '%s',// PAY_txn_id_chq_nmbr |
|
797 | - '%d',// PAY_via_admin |
|
798 | - '%s',// PAY_details |
|
789 | + '%d', // TXN_Id |
|
790 | + '%s', // STS_ID |
|
791 | + '%s', // PAY_timestamp |
|
792 | + '%s', // PAY_method |
|
793 | + '%f', // PAY_amount |
|
794 | + '%s', // PAY_gateway |
|
795 | + '%s', // PAY_gateway_response |
|
796 | + '%s', // PAY_txn_id_chq_nmbr |
|
797 | + '%d', // PAY_via_admin |
|
798 | + '%s', // PAY_details |
|
799 | 799 | ); |
800 | 800 | $success = $wpdb->insert($this->_new_payment_table, $cols_n_values, $datatypes); |
801 | - if (!$success) { |
|
801 | + if ( ! $success) { |
|
802 | 802 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_attendee, $this->_new_attendee_cpt_table, $cols_n_values, $datatypes)); |
803 | 803 | return 0; |
804 | 804 | } |
@@ -817,7 +817,7 @@ discard block |
||
817 | 817 | */ |
818 | 818 | private function _find_mer_primary_attendee_using_mer_tables($old_registration_id) |
819 | 819 | { |
820 | - if (!$this->_mer_tables_exist()) { |
|
820 | + if ( ! $this->_mer_tables_exist()) { |
|
821 | 821 | return false; |
822 | 822 | } |
823 | 823 | global $wpdb; |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.80.rc.065'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.80.rc.065'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
@@ -27,322 +27,322 @@ |
||
27 | 27 | class EE_Brewing_Regular extends EE_BASE implements InterminableInterface |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * @var TableAnalysis $table_analysis |
|
32 | - */ |
|
33 | - protected $_table_analysis; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * EE_Brewing_Regular constructor. |
|
38 | - * |
|
39 | - * @param TableAnalysis $table_analysis |
|
40 | - */ |
|
41 | - public function __construct(TableAnalysis $table_analysis) |
|
42 | - { |
|
43 | - $this->_table_analysis = $table_analysis; |
|
44 | - if (defined('EE_CAFF_PATH')) { |
|
45 | - $this->setInitializationHooks(); |
|
46 | - $this->setApiRegistrationHooks(); |
|
47 | - $this->setSwitchHooks(); |
|
48 | - $this->setDefaultFilterHooks(); |
|
49 | - // caffeinated constructed |
|
50 | - do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
51 | - } |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * Various hooks used for extending features via registration of modules or extensions. |
|
57 | - */ |
|
58 | - private function setApiRegistrationHooks() |
|
59 | - { |
|
60 | - add_filter( |
|
61 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
62 | - array($this, 'caffeinated_modules_to_register') |
|
63 | - ); |
|
64 | - add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
65 | - add_filter( |
|
66 | - 'AHEE__EE_System__load_core_configuration__complete', |
|
67 | - function () { |
|
68 | - EE_Register_Payment_Method::register( |
|
69 | - 'caffeinated_payment_methods', |
|
70 | - array( |
|
71 | - 'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR), |
|
72 | - ) |
|
73 | - ); |
|
74 | - } |
|
75 | - ); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Various hooks used for modifying initialization or activation processes. |
|
81 | - */ |
|
82 | - private function setInitializationHooks() |
|
83 | - { |
|
84 | - // activation |
|
85 | - add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content')); |
|
86 | - // load caff init |
|
87 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init')); |
|
88 | - // load caff scripts |
|
89 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Various hooks used for switch (on/off) type filters. |
|
95 | - */ |
|
96 | - private function setSwitchHooks() |
|
97 | - { |
|
98 | - // remove the "powered by" credit link from receipts and invoices |
|
99 | - add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
100 | - // seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
101 | - add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * Various filters for affecting default configuration values in the caffeinated |
|
107 | - * context. |
|
108 | - */ |
|
109 | - private function setDefaultFilterHooks() |
|
110 | - { |
|
111 | - add_filter( |
|
112 | - 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
113 | - '__return_true' |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
120 | - * |
|
121 | - * @param array $paths original helper paths array |
|
122 | - * @return array new array of paths |
|
123 | - */ |
|
124 | - public function caf_helper_paths($paths) |
|
125 | - { |
|
126 | - $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
127 | - return $paths; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
133 | - * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
134 | - * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
135 | - * This action should only be called when EE 4.x.0.P is initially activated. |
|
136 | - * Right now the only CAF content are these global prices. If there's more in the future, then |
|
137 | - * we should probably create a caf file to contain it all instead just a function like this. |
|
138 | - * Right now, we ASSUME the only price types in the system are default ones |
|
139 | - * |
|
140 | - * @global wpdb $wpdb |
|
141 | - */ |
|
142 | - public function initialize_caf_db_content() |
|
143 | - { |
|
144 | - global $wpdb; |
|
145 | - // use same method of getting creator id as the version introducing the change |
|
146 | - $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
147 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
148 | - $price_table = $wpdb->prefix . "esp_price"; |
|
149 | - if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
150 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';// include trashed price types |
|
151 | - $tax_price_type_count = $wpdb->get_var($SQL); |
|
152 | - if ($tax_price_type_count <= 1) { |
|
153 | - $wpdb->insert( |
|
154 | - $price_type_table, |
|
155 | - array( |
|
156 | - 'PRT_name' => __("Regional Tax", "event_espresso"), |
|
157 | - 'PBT_ID' => 4, |
|
158 | - 'PRT_is_percent' => true, |
|
159 | - 'PRT_order' => 60, |
|
160 | - 'PRT_deleted' => false, |
|
161 | - 'PRT_wp_user' => $default_creator_id, |
|
162 | - ), |
|
163 | - array( |
|
164 | - '%s',// PRT_name |
|
165 | - '%d',// PBT_id |
|
166 | - '%d',// PRT_is_percent |
|
167 | - '%d',// PRT_order |
|
168 | - '%d',// PRT_deleted |
|
169 | - '%d', // PRT_wp_user |
|
170 | - ) |
|
171 | - ); |
|
172 | - // federal tax |
|
173 | - $result = $wpdb->insert( |
|
174 | - $price_type_table, |
|
175 | - array( |
|
176 | - 'PRT_name' => __("Federal Tax", "event_espresso"), |
|
177 | - 'PBT_ID' => 4, |
|
178 | - 'PRT_is_percent' => true, |
|
179 | - 'PRT_order' => 70, |
|
180 | - 'PRT_deleted' => false, |
|
181 | - 'PRT_wp_user' => $default_creator_id, |
|
182 | - ), |
|
183 | - array( |
|
184 | - '%s',// PRT_name |
|
185 | - '%d',// PBT_id |
|
186 | - '%d',// PRT_is_percent |
|
187 | - '%d',// PRT_order |
|
188 | - '%d',// PRT_deleted |
|
189 | - '%d' // PRT_wp_user |
|
190 | - ) |
|
191 | - ); |
|
192 | - if ($result) { |
|
193 | - $wpdb->insert( |
|
194 | - $price_table, |
|
195 | - array( |
|
196 | - 'PRT_ID' => $wpdb->insert_id, |
|
197 | - 'PRC_amount' => 15.00, |
|
198 | - 'PRC_name' => __("Sales Tax", "event_espresso"), |
|
199 | - 'PRC_desc' => '', |
|
200 | - 'PRC_is_default' => true, |
|
201 | - 'PRC_overrides' => null, |
|
202 | - 'PRC_deleted' => false, |
|
203 | - 'PRC_order' => 50, |
|
204 | - 'PRC_parent' => null, |
|
205 | - 'PRC_wp_user' => $default_creator_id, |
|
206 | - ), |
|
207 | - array( |
|
208 | - '%d',// PRT_id |
|
209 | - '%f',// PRC_amount |
|
210 | - '%s',// PRC_name |
|
211 | - '%s',// PRC_desc |
|
212 | - '%d',// PRC_is_default |
|
213 | - '%d',// PRC_overrides |
|
214 | - '%d',// PRC_deleted |
|
215 | - '%d',// PRC_order |
|
216 | - '%d',// PRC_parent |
|
217 | - '%d' // PRC_wp_user |
|
218 | - ) |
|
219 | - ); |
|
220 | - } |
|
221 | - } |
|
222 | - } |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * caffeinated_modules_to_register |
|
228 | - * |
|
229 | - * @access public |
|
230 | - * @param array $modules_to_register |
|
231 | - * @return array |
|
232 | - */ |
|
233 | - public function caffeinated_modules_to_register($modules_to_register = array()) |
|
234 | - { |
|
235 | - if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
236 | - $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
237 | - if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
238 | - $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
239 | - } |
|
240 | - } |
|
241 | - return $modules_to_register; |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * @throws EE_Error |
|
247 | - * @throws InvalidArgumentException |
|
248 | - * @throws ReflectionException |
|
249 | - * @throws InvalidDataTypeException |
|
250 | - * @throws InvalidInterfaceException |
|
251 | - */ |
|
252 | - public function caffeinated_init() |
|
253 | - { |
|
254 | - // Custom Post Type hooks |
|
255 | - add_filter( |
|
256 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
257 | - array($this, 'filter_taxonomies') |
|
258 | - ); |
|
259 | - add_filter( |
|
260 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes', |
|
261 | - array($this, 'filter_cpts') |
|
262 | - ); |
|
263 | - add_filter( |
|
264 | - 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', |
|
265 | - array($this, 'nav_metabox_items') |
|
266 | - ); |
|
267 | - EE_Registry::instance()->load_file( |
|
268 | - EE_CAFF_PATH, |
|
269 | - 'EE_Caf_Messages', |
|
270 | - 'class', |
|
271 | - array(), |
|
272 | - false |
|
273 | - ); |
|
274 | - // caffeinated_init__complete hook |
|
275 | - do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - public function enqueue_caffeinated_scripts() |
|
280 | - { |
|
281 | - // sound of crickets... |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * callbacks below here |
|
287 | - * |
|
288 | - * @param array $taxonomy_array |
|
289 | - * @return array |
|
290 | - */ |
|
291 | - public function filter_taxonomies(array $taxonomy_array) |
|
292 | - { |
|
293 | - $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
294 | - return $taxonomy_array; |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * @param array $cpt_array |
|
300 | - * @return mixed |
|
301 | - */ |
|
302 | - public function filter_cpts(array $cpt_array) |
|
303 | - { |
|
304 | - $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
305 | - return $cpt_array; |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * @param array $menuitems |
|
311 | - * @return array |
|
312 | - */ |
|
313 | - public function nav_metabox_items(array $menuitems) |
|
314 | - { |
|
315 | - $menuitems[] = array( |
|
316 | - 'title' => __('Venue List', 'event_espresso'), |
|
317 | - 'url' => get_post_type_archive_link('espresso_venues'), |
|
318 | - 'description' => __('Archive page for all venues.', 'event_espresso'), |
|
319 | - ); |
|
320 | - return $menuitems; |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * Gets the injected table analyzer, or throws an exception |
|
326 | - * |
|
327 | - * @return TableAnalysis |
|
328 | - * @throws \EE_Error |
|
329 | - */ |
|
330 | - protected function _get_table_analysis() |
|
331 | - { |
|
332 | - if ($this->_table_analysis instanceof TableAnalysis) { |
|
333 | - return $this->_table_analysis; |
|
334 | - } else { |
|
335 | - throw new \EE_Error( |
|
336 | - sprintf( |
|
337 | - __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
338 | - get_class($this) |
|
339 | - ) |
|
340 | - ); |
|
341 | - } |
|
342 | - } |
|
30 | + /** |
|
31 | + * @var TableAnalysis $table_analysis |
|
32 | + */ |
|
33 | + protected $_table_analysis; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * EE_Brewing_Regular constructor. |
|
38 | + * |
|
39 | + * @param TableAnalysis $table_analysis |
|
40 | + */ |
|
41 | + public function __construct(TableAnalysis $table_analysis) |
|
42 | + { |
|
43 | + $this->_table_analysis = $table_analysis; |
|
44 | + if (defined('EE_CAFF_PATH')) { |
|
45 | + $this->setInitializationHooks(); |
|
46 | + $this->setApiRegistrationHooks(); |
|
47 | + $this->setSwitchHooks(); |
|
48 | + $this->setDefaultFilterHooks(); |
|
49 | + // caffeinated constructed |
|
50 | + do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
51 | + } |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * Various hooks used for extending features via registration of modules or extensions. |
|
57 | + */ |
|
58 | + private function setApiRegistrationHooks() |
|
59 | + { |
|
60 | + add_filter( |
|
61 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
62 | + array($this, 'caffeinated_modules_to_register') |
|
63 | + ); |
|
64 | + add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
65 | + add_filter( |
|
66 | + 'AHEE__EE_System__load_core_configuration__complete', |
|
67 | + function () { |
|
68 | + EE_Register_Payment_Method::register( |
|
69 | + 'caffeinated_payment_methods', |
|
70 | + array( |
|
71 | + 'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR), |
|
72 | + ) |
|
73 | + ); |
|
74 | + } |
|
75 | + ); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Various hooks used for modifying initialization or activation processes. |
|
81 | + */ |
|
82 | + private function setInitializationHooks() |
|
83 | + { |
|
84 | + // activation |
|
85 | + add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content')); |
|
86 | + // load caff init |
|
87 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init')); |
|
88 | + // load caff scripts |
|
89 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Various hooks used for switch (on/off) type filters. |
|
95 | + */ |
|
96 | + private function setSwitchHooks() |
|
97 | + { |
|
98 | + // remove the "powered by" credit link from receipts and invoices |
|
99 | + add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
100 | + // seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
101 | + add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * Various filters for affecting default configuration values in the caffeinated |
|
107 | + * context. |
|
108 | + */ |
|
109 | + private function setDefaultFilterHooks() |
|
110 | + { |
|
111 | + add_filter( |
|
112 | + 'FHEE__EE_Admin_Config__show_reg_footer__default', |
|
113 | + '__return_true' |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
120 | + * |
|
121 | + * @param array $paths original helper paths array |
|
122 | + * @return array new array of paths |
|
123 | + */ |
|
124 | + public function caf_helper_paths($paths) |
|
125 | + { |
|
126 | + $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
127 | + return $paths; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
133 | + * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
134 | + * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
135 | + * This action should only be called when EE 4.x.0.P is initially activated. |
|
136 | + * Right now the only CAF content are these global prices. If there's more in the future, then |
|
137 | + * we should probably create a caf file to contain it all instead just a function like this. |
|
138 | + * Right now, we ASSUME the only price types in the system are default ones |
|
139 | + * |
|
140 | + * @global wpdb $wpdb |
|
141 | + */ |
|
142 | + public function initialize_caf_db_content() |
|
143 | + { |
|
144 | + global $wpdb; |
|
145 | + // use same method of getting creator id as the version introducing the change |
|
146 | + $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
147 | + $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
148 | + $price_table = $wpdb->prefix . "esp_price"; |
|
149 | + if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
150 | + $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';// include trashed price types |
|
151 | + $tax_price_type_count = $wpdb->get_var($SQL); |
|
152 | + if ($tax_price_type_count <= 1) { |
|
153 | + $wpdb->insert( |
|
154 | + $price_type_table, |
|
155 | + array( |
|
156 | + 'PRT_name' => __("Regional Tax", "event_espresso"), |
|
157 | + 'PBT_ID' => 4, |
|
158 | + 'PRT_is_percent' => true, |
|
159 | + 'PRT_order' => 60, |
|
160 | + 'PRT_deleted' => false, |
|
161 | + 'PRT_wp_user' => $default_creator_id, |
|
162 | + ), |
|
163 | + array( |
|
164 | + '%s',// PRT_name |
|
165 | + '%d',// PBT_id |
|
166 | + '%d',// PRT_is_percent |
|
167 | + '%d',// PRT_order |
|
168 | + '%d',// PRT_deleted |
|
169 | + '%d', // PRT_wp_user |
|
170 | + ) |
|
171 | + ); |
|
172 | + // federal tax |
|
173 | + $result = $wpdb->insert( |
|
174 | + $price_type_table, |
|
175 | + array( |
|
176 | + 'PRT_name' => __("Federal Tax", "event_espresso"), |
|
177 | + 'PBT_ID' => 4, |
|
178 | + 'PRT_is_percent' => true, |
|
179 | + 'PRT_order' => 70, |
|
180 | + 'PRT_deleted' => false, |
|
181 | + 'PRT_wp_user' => $default_creator_id, |
|
182 | + ), |
|
183 | + array( |
|
184 | + '%s',// PRT_name |
|
185 | + '%d',// PBT_id |
|
186 | + '%d',// PRT_is_percent |
|
187 | + '%d',// PRT_order |
|
188 | + '%d',// PRT_deleted |
|
189 | + '%d' // PRT_wp_user |
|
190 | + ) |
|
191 | + ); |
|
192 | + if ($result) { |
|
193 | + $wpdb->insert( |
|
194 | + $price_table, |
|
195 | + array( |
|
196 | + 'PRT_ID' => $wpdb->insert_id, |
|
197 | + 'PRC_amount' => 15.00, |
|
198 | + 'PRC_name' => __("Sales Tax", "event_espresso"), |
|
199 | + 'PRC_desc' => '', |
|
200 | + 'PRC_is_default' => true, |
|
201 | + 'PRC_overrides' => null, |
|
202 | + 'PRC_deleted' => false, |
|
203 | + 'PRC_order' => 50, |
|
204 | + 'PRC_parent' => null, |
|
205 | + 'PRC_wp_user' => $default_creator_id, |
|
206 | + ), |
|
207 | + array( |
|
208 | + '%d',// PRT_id |
|
209 | + '%f',// PRC_amount |
|
210 | + '%s',// PRC_name |
|
211 | + '%s',// PRC_desc |
|
212 | + '%d',// PRC_is_default |
|
213 | + '%d',// PRC_overrides |
|
214 | + '%d',// PRC_deleted |
|
215 | + '%d',// PRC_order |
|
216 | + '%d',// PRC_parent |
|
217 | + '%d' // PRC_wp_user |
|
218 | + ) |
|
219 | + ); |
|
220 | + } |
|
221 | + } |
|
222 | + } |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * caffeinated_modules_to_register |
|
228 | + * |
|
229 | + * @access public |
|
230 | + * @param array $modules_to_register |
|
231 | + * @return array |
|
232 | + */ |
|
233 | + public function caffeinated_modules_to_register($modules_to_register = array()) |
|
234 | + { |
|
235 | + if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
236 | + $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
237 | + if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
238 | + $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
239 | + } |
|
240 | + } |
|
241 | + return $modules_to_register; |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * @throws EE_Error |
|
247 | + * @throws InvalidArgumentException |
|
248 | + * @throws ReflectionException |
|
249 | + * @throws InvalidDataTypeException |
|
250 | + * @throws InvalidInterfaceException |
|
251 | + */ |
|
252 | + public function caffeinated_init() |
|
253 | + { |
|
254 | + // Custom Post Type hooks |
|
255 | + add_filter( |
|
256 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
257 | + array($this, 'filter_taxonomies') |
|
258 | + ); |
|
259 | + add_filter( |
|
260 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes', |
|
261 | + array($this, 'filter_cpts') |
|
262 | + ); |
|
263 | + add_filter( |
|
264 | + 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', |
|
265 | + array($this, 'nav_metabox_items') |
|
266 | + ); |
|
267 | + EE_Registry::instance()->load_file( |
|
268 | + EE_CAFF_PATH, |
|
269 | + 'EE_Caf_Messages', |
|
270 | + 'class', |
|
271 | + array(), |
|
272 | + false |
|
273 | + ); |
|
274 | + // caffeinated_init__complete hook |
|
275 | + do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + public function enqueue_caffeinated_scripts() |
|
280 | + { |
|
281 | + // sound of crickets... |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * callbacks below here |
|
287 | + * |
|
288 | + * @param array $taxonomy_array |
|
289 | + * @return array |
|
290 | + */ |
|
291 | + public function filter_taxonomies(array $taxonomy_array) |
|
292 | + { |
|
293 | + $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
294 | + return $taxonomy_array; |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * @param array $cpt_array |
|
300 | + * @return mixed |
|
301 | + */ |
|
302 | + public function filter_cpts(array $cpt_array) |
|
303 | + { |
|
304 | + $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
305 | + return $cpt_array; |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * @param array $menuitems |
|
311 | + * @return array |
|
312 | + */ |
|
313 | + public function nav_metabox_items(array $menuitems) |
|
314 | + { |
|
315 | + $menuitems[] = array( |
|
316 | + 'title' => __('Venue List', 'event_espresso'), |
|
317 | + 'url' => get_post_type_archive_link('espresso_venues'), |
|
318 | + 'description' => __('Archive page for all venues.', 'event_espresso'), |
|
319 | + ); |
|
320 | + return $menuitems; |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * Gets the injected table analyzer, or throws an exception |
|
326 | + * |
|
327 | + * @return TableAnalysis |
|
328 | + * @throws \EE_Error |
|
329 | + */ |
|
330 | + protected function _get_table_analysis() |
|
331 | + { |
|
332 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
333 | + return $this->_table_analysis; |
|
334 | + } else { |
|
335 | + throw new \EE_Error( |
|
336 | + sprintf( |
|
337 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
338 | + get_class($this) |
|
339 | + ) |
|
340 | + ); |
|
341 | + } |
|
342 | + } |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | |
346 | 346 | $brewing = new EE_Brewing_Regular( |
347 | - EE_Registry::instance()->create('TableAnalysis', array(), true) |
|
347 | + EE_Registry::instance()->create('TableAnalysis', array(), true) |
|
348 | 348 | ); |
@@ -11,10 +11,10 @@ discard block |
||
11 | 11 | * define and use the hook in a specific caffeinated/whatever class or file. |
12 | 12 | */ |
13 | 13 | // defined some new constants related to caffeinated folder |
14 | -define('EE_CAF_URL', EE_PLUGIN_DIR_URL . 'caffeinated/'); |
|
15 | -define('EE_CAF_CORE', EE_CAFF_PATH . 'core' . DS); |
|
16 | -define('EE_CAF_LIBRARIES', EE_CAF_CORE . 'libraries' . DS); |
|
17 | -define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH . 'payment_methods' . DS); |
|
14 | +define('EE_CAF_URL', EE_PLUGIN_DIR_URL.'caffeinated/'); |
|
15 | +define('EE_CAF_CORE', EE_CAFF_PATH.'core'.DS); |
|
16 | +define('EE_CAF_LIBRARIES', EE_CAF_CORE.'libraries'.DS); |
|
17 | +define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH.'payment_methods'.DS); |
|
18 | 18 | |
19 | 19 | |
20 | 20 | /** |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
65 | 65 | add_filter( |
66 | 66 | 'AHEE__EE_System__load_core_configuration__complete', |
67 | - function () { |
|
67 | + function() { |
|
68 | 68 | EE_Register_Payment_Method::register( |
69 | 69 | 'caffeinated_payment_methods', |
70 | 70 | array( |
71 | - 'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR), |
|
71 | + 'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS.'*', GLOB_ONLYDIR), |
|
72 | 72 | ) |
73 | 73 | ); |
74 | 74 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | public function caf_helper_paths($paths) |
125 | 125 | { |
126 | - $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
126 | + $paths[] = EE_CAF_CORE.'helpers'.DS; |
|
127 | 127 | return $paths; |
128 | 128 | } |
129 | 129 | |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | global $wpdb; |
145 | 145 | // use same method of getting creator id as the version introducing the change |
146 | 146 | $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
147 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
148 | - $price_table = $wpdb->prefix . "esp_price"; |
|
147 | + $price_type_table = $wpdb->prefix."esp_price_type"; |
|
148 | + $price_table = $wpdb->prefix."esp_price"; |
|
149 | 149 | if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
150 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';// include trashed price types |
|
150 | + $SQL = 'SELECT COUNT(PRT_ID) FROM '.$price_type_table.' WHERE PBT_ID=4'; // include trashed price types |
|
151 | 151 | $tax_price_type_count = $wpdb->get_var($SQL); |
152 | 152 | if ($tax_price_type_count <= 1) { |
153 | 153 | $wpdb->insert( |
@@ -161,11 +161,11 @@ discard block |
||
161 | 161 | 'PRT_wp_user' => $default_creator_id, |
162 | 162 | ), |
163 | 163 | array( |
164 | - '%s',// PRT_name |
|
165 | - '%d',// PBT_id |
|
166 | - '%d',// PRT_is_percent |
|
167 | - '%d',// PRT_order |
|
168 | - '%d',// PRT_deleted |
|
164 | + '%s', // PRT_name |
|
165 | + '%d', // PBT_id |
|
166 | + '%d', // PRT_is_percent |
|
167 | + '%d', // PRT_order |
|
168 | + '%d', // PRT_deleted |
|
169 | 169 | '%d', // PRT_wp_user |
170 | 170 | ) |
171 | 171 | ); |
@@ -181,11 +181,11 @@ discard block |
||
181 | 181 | 'PRT_wp_user' => $default_creator_id, |
182 | 182 | ), |
183 | 183 | array( |
184 | - '%s',// PRT_name |
|
185 | - '%d',// PBT_id |
|
186 | - '%d',// PRT_is_percent |
|
187 | - '%d',// PRT_order |
|
188 | - '%d',// PRT_deleted |
|
184 | + '%s', // PRT_name |
|
185 | + '%d', // PBT_id |
|
186 | + '%d', // PRT_is_percent |
|
187 | + '%d', // PRT_order |
|
188 | + '%d', // PRT_deleted |
|
189 | 189 | '%d' // PRT_wp_user |
190 | 190 | ) |
191 | 191 | ); |
@@ -205,15 +205,15 @@ discard block |
||
205 | 205 | 'PRC_wp_user' => $default_creator_id, |
206 | 206 | ), |
207 | 207 | array( |
208 | - '%d',// PRT_id |
|
209 | - '%f',// PRC_amount |
|
210 | - '%s',// PRC_name |
|
211 | - '%s',// PRC_desc |
|
212 | - '%d',// PRC_is_default |
|
213 | - '%d',// PRC_overrides |
|
214 | - '%d',// PRC_deleted |
|
215 | - '%d',// PRC_order |
|
216 | - '%d',// PRC_parent |
|
208 | + '%d', // PRT_id |
|
209 | + '%f', // PRC_amount |
|
210 | + '%s', // PRC_name |
|
211 | + '%s', // PRC_desc |
|
212 | + '%d', // PRC_is_default |
|
213 | + '%d', // PRC_overrides |
|
214 | + '%d', // PRC_deleted |
|
215 | + '%d', // PRC_order |
|
216 | + '%d', // PRC_parent |
|
217 | 217 | '%d' // PRC_wp_user |
218 | 218 | ) |
219 | 219 | ); |
@@ -232,8 +232,8 @@ discard block |
||
232 | 232 | */ |
233 | 233 | public function caffeinated_modules_to_register($modules_to_register = array()) |
234 | 234 | { |
235 | - if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
236 | - $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
235 | + if (is_readable(EE_CAFF_PATH.'modules')) { |
|
236 | + $caffeinated_modules_to_register = glob(EE_CAFF_PATH.'modules'.DS.'*', GLOB_ONLYDIR); |
|
237 | 237 | if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
238 | 238 | $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
239 | 239 | } |