TestCommandHandler.php
240 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @copyright © TMS-Plugins. All rights reserved. |
| 4 | * @licence See LICENCE.md for license details. |
| 5 | */ |
| 6 | |
| 7 | namespace AmeliaBooking\Application\Commands\Test; |
| 8 | |
| 9 | use AmeliaBooking\Application\Commands\CommandHandler; |
| 10 | use AmeliaBooking\Application\Commands\CommandResult; |
| 11 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 12 | use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException; |
| 13 | use AmeliaBooking\Infrastructure\Repository\User\UserRepository; |
| 14 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Bookable\CategoriesTable; |
| 15 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Bookable\ExtrasTable; |
| 16 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Bookable\PackagesCustomersServicesTable; |
| 17 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Bookable\PackagesCustomersTable; |
| 18 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Bookable\PackagesServicesLocationsTable; |
| 19 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Bookable\PackagesServicesProvidersTable; |
| 20 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Bookable\PackagesServicesTable; |
| 21 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Bookable\PackagesTable; |
| 22 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Bookable\ResourcesToEntitiesTable; |
| 23 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Bookable\ServicesTable; |
| 24 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Booking\AppointmentsTable; |
| 25 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Booking\CustomerBookingsTable; |
| 26 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Booking\CustomerBookingsToEventsPeriodsTable; |
| 27 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Booking\CustomerBookingsToExtrasTable; |
| 28 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Booking\CustomerBookingToEventsTicketsTable; |
| 29 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Booking\EventsPeriodsTable; |
| 30 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Booking\EventsProvidersTable; |
| 31 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Booking\EventsTable; |
| 32 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Booking\EventsTagsTable; |
| 33 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Booking\EventsTicketsTable; |
| 34 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Coupon\CouponsTable; |
| 35 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Coupon\CouponsToEventsTable; |
| 36 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Coupon\CouponsToPackagesTable; |
| 37 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Coupon\CouponsToServicesTable; |
| 38 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\CustomField\CustomFieldsEventsTable; |
| 39 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\CustomField\CustomFieldsServicesTable; |
| 40 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\CustomField\CustomFieldsTable; |
| 41 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Location\LocationsTable; |
| 42 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Notification\NotificationsToEntitiesTable; |
| 43 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\Payment\PaymentsTable; |
| 44 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\User\Provider\ProvidersLocationTable; |
| 45 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\User\Provider\ProvidersPeriodLocationTable; |
| 46 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\User\Provider\ProvidersPeriodServiceTable; |
| 47 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\User\Provider\ProvidersPeriodTable; |
| 48 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\User\Provider\ProvidersServiceTable; |
| 49 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\User\Provider\ProvidersSpecialDayPeriodLocationTable; |
| 50 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\User\Provider\ProvidersSpecialDayPeriodTable; |
| 51 | use AmeliaBooking\Infrastructure\WP\InstallActions\DB\User\UsersTable; |
| 52 | use Interop\Container\Exception\ContainerException; |
| 53 | |
| 54 | /** |
| 55 | * Class TestCommandHandler |
| 56 | * |
| 57 | * @package AmeliaBooking\Application\Commands\Test |
| 58 | */ |
| 59 | class TestCommandHandler extends CommandHandler |
| 60 | { |
| 61 | /** |
| 62 | * @param TestCommand $command |
| 63 | * |
| 64 | * @return CommandResult |
| 65 | * |
| 66 | * @throws ContainerException |
| 67 | * @throws InvalidArgumentException |
| 68 | * @throws QueryExecutionException |
| 69 | */ |
| 70 | public function handle(TestCommand $command) |
| 71 | { |
| 72 | $result = new CommandResult(); |
| 73 | |
| 74 | $this->checkMandatoryFields($command); |
| 75 | |
| 76 | $items = [ |
| 77 | AppointmentsTable::getTableName() => [ |
| 78 | 'serviceId' => ServicesTable::getTableName(), |
| 79 | 'providerId' => UsersTable::getTableName(), |
| 80 | 'locationId' => LocationsTable::getTableName(), |
| 81 | 'parentId' => AppointmentsTable::getTableName(), |
| 82 | ], |
| 83 | CouponsToEventsTable::getTableName() => [ |
| 84 | 'couponId' => CouponsTable::getTableName(), |
| 85 | 'eventId' => EventsTable::getTableName(), |
| 86 | ], |
| 87 | CouponsToPackagesTable::getTableName() => [ |
| 88 | 'couponId' => CouponsTable::getTableName(), |
| 89 | 'packageId' => PackagesTable::getTableName(), |
| 90 | ], |
| 91 | CouponsToServicesTable::getTableName() => [ |
| 92 | 'couponId' => CouponsTable::getTableName(), |
| 93 | 'serviceId' => ServicesTable::getTableName(), |
| 94 | ], |
| 95 | CustomerBookingsTable::getTableName() => [ |
| 96 | 'appointmentId' => AppointmentsTable::getTableName(), |
| 97 | 'customerId' => UsersTable::getTableName(), |
| 98 | 'couponId' => CouponsTable::getTableName(), |
| 99 | ], |
| 100 | CustomerBookingsToEventsPeriodsTable::getTableName() => [ |
| 101 | 'customerBookingId' => CustomerBookingsTable::getTableName(), |
| 102 | 'eventPeriodId' => EventsPeriodsTable::getTableName(), |
| 103 | ], |
| 104 | CustomerBookingToEventsTicketsTable::getTableName() => [ |
| 105 | 'customerBookingId' => CustomerBookingsTable::getTableName(), |
| 106 | 'eventTicketId' => EventsTicketsTable::getTableName(), |
| 107 | ], |
| 108 | CustomerBookingsToExtrasTable::getTableName() => [ |
| 109 | 'customerBookingId' => CustomerBookingsTable::getTableName(), |
| 110 | 'extraId' => ExtrasTable::getTableName(), |
| 111 | ], |
| 112 | CustomFieldsEventsTable::getTableName() => [ |
| 113 | 'customFieldId' => CustomFieldsTable::getTableName(), |
| 114 | 'eventId' => EventsTable::getTableName(), |
| 115 | ], |
| 116 | CustomFieldsServicesTable::getTableName() => [ |
| 117 | 'customFieldId' => CustomFieldsTable::getTableName(), |
| 118 | 'serviceId' => ServicesTable::getTableName(), |
| 119 | ], |
| 120 | EventsTable::getTableName() => [ |
| 121 | 'parentId' => EventsTable::getTableName(), |
| 122 | 'locationId' => LocationsTable::getTableName(), |
| 123 | 'organizerId' => UsersTable::getTableName(), |
| 124 | ], |
| 125 | EventsPeriodsTable::getTableName() => [ |
| 126 | 'eventId' => EventsTable::getTableName(), |
| 127 | ], |
| 128 | EventsTagsTable::getTableName() => [ |
| 129 | 'eventId' => EventsTable::getTableName(), |
| 130 | ], |
| 131 | EventsProvidersTable::getTableName() => [ |
| 132 | 'eventId' => EventsTable::getTableName(), |
| 133 | 'userId' => UsersTable::getTableName(), |
| 134 | ], |
| 135 | EventsTicketsTable::getTableName() => [ |
| 136 | 'eventId' => EventsTable::getTableName(), |
| 137 | ], |
| 138 | ExtrasTable::getTableName() => [ |
| 139 | 'serviceId' => ServicesTable::getTableName(), |
| 140 | ], |
| 141 | NotificationsToEntitiesTable::getTableName() => [ |
| 142 | 'entityId/entity/appointment' => ServicesTable::getTableName(), |
| 143 | 'entityId/entity/event' => EventsTable::getTableName(), |
| 144 | ], |
| 145 | PackagesCustomersServicesTable::getTableName() => [ |
| 146 | 'packageCustomerId' => PackagesCustomersTable::getTableName(), |
| 147 | 'serviceId' => ServicesTable::getTableName(), |
| 148 | 'providerId' => UsersTable::getTableName(), |
| 149 | 'locationId' => LocationsTable::getTableName(), |
| 150 | ], |
| 151 | PackagesServicesLocationsTable::getTableName() => [ |
| 152 | 'packageServiceId' => PackagesServicesTable::getTableName(), |
| 153 | 'locationId' => LocationsTable::getTableName(), |
| 154 | ], |
| 155 | PackagesServicesProvidersTable::getTableName() => [ |
| 156 | 'packageServiceId' => PackagesServicesTable::getTableName(), |
| 157 | 'userId' => UsersTable::getTableName(), |
| 158 | ], |
| 159 | PackagesCustomersTable::getTableName() => [ |
| 160 | 'packageId' => PackagesTable::getTableName(), |
| 161 | 'customerId' => UsersTable::getTableName(), |
| 162 | 'couponId' => CouponsTable::getTableName(), |
| 163 | ], |
| 164 | PackagesServicesTable::getTableName() => [ |
| 165 | 'serviceId' => ServicesTable::getTableName(), |
| 166 | 'packageId' => PackagesTable::getTableName(), |
| 167 | ], |
| 168 | PaymentsTable::getTableName() => [ |
| 169 | 'customerBookingId' => CustomerBookingsTable::getTableName(), |
| 170 | 'packageCustomerId' => PackagesCustomersTable::getTableName(), |
| 171 | 'parentId' => PaymentsTable::getTableName(), |
| 172 | ], |
| 173 | ProvidersLocationTable::getTableName() => [ |
| 174 | 'locationId' => LocationsTable::getTableName(), |
| 175 | ], |
| 176 | ProvidersPeriodTable::getTableName() => [ |
| 177 | 'locationId' => LocationsTable::getTableName(), |
| 178 | ], |
| 179 | ProvidersPeriodLocationTable::getTableName() => [ |
| 180 | 'locationId' => LocationsTable::getTableName(), |
| 181 | ], |
| 182 | ProvidersPeriodServiceTable::getTableName() => [ |
| 183 | 'serviceId' => ServicesTable::getTableName(), |
| 184 | ], |
| 185 | ProvidersServiceTable::getTableName() => [ |
| 186 | 'userId' => UsersTable::getTableName(), |
| 187 | 'serviceId' => ServicesTable::getTableName(), |
| 188 | ], |
| 189 | ProvidersSpecialDayPeriodTable::getTableName() => [ |
| 190 | 'locationId' => LocationsTable::getTableName(), |
| 191 | ], |
| 192 | ProvidersSpecialDayPeriodLocationTable::getTableName() => [ |
| 193 | 'locationId' => LocationsTable::getTableName(), |
| 194 | ], |
| 195 | ServicesTable::getTableName() => [ |
| 196 | 'categoryId' => CategoriesTable::getTableName(), |
| 197 | ], |
| 198 | ResourcesToEntitiesTable::getTableName() => [ |
| 199 | 'entityId/entityType/service' => ServicesTable::getTableName(), |
| 200 | 'entityId/entityType/employee' => UsersTable::getTableName(), |
| 201 | 'entityId/entityType/location' => LocationsTable::getTableName(), |
| 202 | ], |
| 203 | ]; |
| 204 | |
| 205 | $messages = []; |
| 206 | |
| 207 | /** @var UserRepository $userRepository */ |
| 208 | $userRepository = $this->getContainer()->get('domain.users.repository'); |
| 209 | |
| 210 | foreach ($items as $testTableName => $testTableData) { |
| 211 | foreach ($testTableData as $testColumnName => $targetTableName) { |
| 212 | $columnData = explode('/', $testColumnName); |
| 213 | |
| 214 | $message = $userRepository->getMissingData( |
| 215 | $testTableName, |
| 216 | $columnData[0], |
| 217 | $targetTableName, |
| 218 | 'id', |
| 219 | sizeof($columnData) === 1 ? null : $columnData[1], |
| 220 | sizeof($columnData) === 1 ? null : $columnData[2] |
| 221 | ); |
| 222 | |
| 223 | if ($message) { |
| 224 | $messages[] = $message; |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 230 | $result->setMessage('Successfully checked data'); |
| 231 | $result->setData( |
| 232 | [ |
| 233 | 'messages' => $messages, |
| 234 | ] |
| 235 | ); |
| 236 | |
| 237 | return $result; |
| 238 | } |
| 239 | } |
| 240 |