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