CI / Tests (PHP 8.2) (pull_request) Successful in 58s
CI / Tests (PHP 8.1) (pull_request) Successful in 58s
CI / No Debug Code (pull_request) Successful in 3s
CI / Coding Standards (pull_request) Successful in 2m53s
CI / PHPStan (pull_request) Successful in 3m0s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m42s
CI / Build Plugin Zip (pull_request) Skipped
Every account-signup question was asked of everybody who registered, on the same terms: "school and grade" had to be put to an adult signing themselves up, and a question a studio needed answered for each student could only be made required by demanding it of everyone. A question now carries an audience — everyone, or only the students someone registers on behalf of — and its own required flag for each side, so optional for you and required for every student you enrol is expressible. Both settings are account-scope only: an offering asks its questions once, about the student being booked, so there is no second audience to differ from, and an offering question mirrors its single "required" into both columns. Every caller reads askedOfSelf()/isRequiredForSelf()/isRequiredForChild() rather than the raw flags, so a students-only question can neither block the account holder nor have an answer filed against them by a crafted post. The family screen, which only ever adds a student, is held to the students' rule. is_required_child arrives from dbDelta defaulting to 0, which would quietly stop every existing required question being required of the students a guardian registers — the case it most likely existed for. A one-time backfill copies is_required across, guarded by its own option so a question later made optional for students stays that way. Closes #163 Co-Authored-By: Claude Opus 5 <[email protected]>
130 lines
6.8 KiB
PHP
130 lines
6.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular;
|
|
|
|
use Unsupervised\Schedular\Auth\DeletedUserCleanup;
|
|
use Unsupervised\Schedular\Auth\EmailConfirmationHandler;
|
|
use Unsupervised\Schedular\Auth\InviteRepository;
|
|
use Unsupervised\Schedular\Auth\AccountPage;
|
|
use Unsupervised\Schedular\Auth\LoginPage;
|
|
use Unsupervised\Schedular\Auth\RegistrationLoginGate;
|
|
use Unsupervised\Schedular\Auth\RegistrationMailer;
|
|
use Unsupervised\Schedular\Auth\RegistrationPage;
|
|
use Unsupervised\Schedular\Auth\RoleManager;
|
|
use Unsupervised\Schedular\Auth\StudentAdminGuard;
|
|
use Unsupervised\Schedular\Booking\BookingPage;
|
|
use Unsupervised\Schedular\Availability\AvailabilityRepository;
|
|
use Unsupervised\Schedular\Booking\BookingRepository;
|
|
use Unsupervised\Schedular\GroupClass\EnrollmentRepository;
|
|
use Unsupervised\Schedular\GroupClass\GroupAccessRepository;
|
|
use Unsupervised\Schedular\GroupClass\GroupClassPage;
|
|
use Unsupervised\Schedular\Guardian\ChildLoginGate;
|
|
use Unsupervised\Schedular\Guardian\FamilyPage;
|
|
use Unsupervised\Schedular\Guardian\GuardianRepository;
|
|
use Unsupervised\Schedular\Guardian\GuardianService;
|
|
use Unsupervised\Schedular\Offering\OfferingRepository;
|
|
use Unsupervised\Schedular\Payment\BillingMethodResolver;
|
|
use Unsupervised\Schedular\Payment\CreditRepository;
|
|
use Unsupervised\Schedular\Payment\PaymentRepository;
|
|
use Unsupervised\Schedular\Payment\PaymentDueMailer;
|
|
use Unsupervised\Schedular\Payment\PaymentService;
|
|
use Unsupervised\Schedular\Payment\ReceiptMailer;
|
|
use Unsupervised\Schedular\Payment\ScheduledBillingRunner;
|
|
use Unsupervised\Schedular\Payment\StripeGateway;
|
|
use Unsupervised\Schedular\Payment\StudioSettings;
|
|
use Unsupervised\Schedular\Policy\AcceptanceRepository;
|
|
use Unsupervised\Schedular\Policy\PolicyRepository;
|
|
use Unsupervised\Schedular\Policy\PolicyService;
|
|
use Unsupervised\Schedular\Policy\PolicyVersionRepository;
|
|
use Unsupervised\Schedular\Registration\AnswerRepository;
|
|
use Unsupervised\Schedular\Registration\QuestionRepository;
|
|
use Unsupervised\Schedular\Registration\RegistrationGate;
|
|
use Unsupervised\Schedular\Update\UpdateChecker;
|
|
|
|
class Plugin {
|
|
|
|
public static function boot(): void {
|
|
load_plugin_textdomain( 'unsupervised-schedular', false, dirname( plugin_basename( USC_PLUGIN_FILE ) ) . '/languages' );
|
|
|
|
global $wpdb;
|
|
if ( ! $wpdb instanceof \wpdb ) {
|
|
return;
|
|
}
|
|
|
|
// Re-run install steps when the plugin files were updated without a fresh
|
|
// activation (e.g. a deploy), so schema and data migrations still apply.
|
|
if ( get_option( 'us_schedular_version' ) !== USC_VERSION ) {
|
|
( new Installer() )->run();
|
|
}
|
|
|
|
$availability = new AvailabilityRepository( $wpdb );
|
|
$bookings = new BookingRepository( $wpdb );
|
|
$offerings = new OfferingRepository( $wpdb );
|
|
$questions = new QuestionRepository( $wpdb );
|
|
|
|
// One-time repair for sites where dbDelta left us_questions.offering_id
|
|
// NOT NULL (it does not reliably relax NULL-ability), which breaks
|
|
// account-scope registration questions. Guarded by its own flag rather
|
|
// than the version gate, since affected sites may already be on the
|
|
// current version. The flag is only set once the ALTER succeeds.
|
|
if ( '1' !== get_option( 'us_questions_offering_nullable', '' ) && $questions->ensureOfferingNullable() ) {
|
|
update_option( 'us_questions_offering_nullable', '1' );
|
|
}
|
|
|
|
// One-time backfill of us_questions.is_required_child, which dbDelta adds
|
|
// defaulting to 0 — leaving every question that *was* required no longer
|
|
// required of the students a guardian registers. Runs after the version
|
|
// gate above, so the column it writes to exists. Guarded so a question
|
|
// later made optional for students stays that way.
|
|
if ( '1' !== get_option( 'us_questions_child_required_backfilled', '' ) && $questions->backfillChildRequired() ) {
|
|
update_option( 'us_questions_child_required_backfilled', '1' );
|
|
}
|
|
|
|
$answers = new AnswerRepository( $wpdb );
|
|
$policies = new PolicyRepository( $wpdb );
|
|
$policyVersions = new PolicyVersionRepository( $wpdb );
|
|
$policyService = new PolicyService( $policies, $policyVersions );
|
|
$acceptances = new AcceptanceRepository( $wpdb );
|
|
$invites = new InviteRepository( $wpdb );
|
|
$enrollments = new EnrollmentRepository( $wpdb );
|
|
$groupAccess = new GroupAccessRepository( $wpdb );
|
|
$registrationGate = new RegistrationGate( $questions, $answers, $policies, $policyVersions, $acceptances );
|
|
|
|
$guardianRepo = new GuardianRepository( $wpdb );
|
|
$guardians = new GuardianService( $guardianRepo, $bookings, $enrollments );
|
|
|
|
$paymentRepo = new PaymentRepository( $wpdb );
|
|
$creditRepo = new CreditRepository( $wpdb );
|
|
$settings = new StudioSettings();
|
|
$resolver = new BillingMethodResolver( $settings );
|
|
$stripe = new StripeGateway( $settings );
|
|
$paymentService = new PaymentService( $paymentRepo, $resolver, new ReceiptMailer(), $bookings, $enrollments, $settings, $stripe, $creditRepo );
|
|
|
|
// The shortcode and block wrappers share the same page objects so
|
|
// front-end output is identical whichever way a page embeds them.
|
|
$registrationMailer = new RegistrationMailer();
|
|
|
|
$bookingPage = new BookingPage( $guardians );
|
|
$loginPage = new LoginPage();
|
|
$registrationPage = new RegistrationPage( $invites, $policies, $policyVersions, $acceptances, $settings, $registrationMailer, $questions, $answers, $groupAccess, $guardians );
|
|
$groupClassPage = new GroupClassPage( $guardians );
|
|
$familyPage = new FamilyPage( $guardians, $questions, $answers );
|
|
$accountPage = new AccountPage();
|
|
|
|
( new ScheduledBillingRunner( $paymentService, $bookings, $enrollments, $offerings, new PaymentDueMailer(), $guardians ) )->register();
|
|
|
|
( new UpdateChecker() )->register();
|
|
( new RoleManager() )->register();
|
|
( new RegistrationLoginGate() )->register();
|
|
( new ChildLoginGate() )->register();
|
|
( new StudentAdminGuard() )->register();
|
|
( new DeletedUserCleanup( $bookings, $availability, $enrollments, $paymentService, $guardianRepo, $guardians ) )->register();
|
|
( new EmailConfirmationHandler( $settings, $registrationMailer ) )->register();
|
|
( new AdminMenu( $availability, $bookings, $offerings, $questions, $answers, $policies, $policyVersions, $policyService, $acceptances, $invites, $enrollments, $groupAccess, $settings, $paymentRepo, $paymentService, $resolver, $registrationMailer, $creditRepo, $guardians ) )->register();
|
|
( new RestRegistrar( $availability, $bookings, $offerings, $questions, $policies, $policyVersions, $policyService, $registrationGate, $enrollments, $groupAccess, $paymentService, $guardians ) )->register();
|
|
( new ShortcodeRegistrar( $bookingPage, $loginPage, $registrationPage, $groupClassPage, $familyPage, $accountPage ) )->register();
|
|
( new BlockRegistrar( $bookingPage, $loginPage, $registrationPage, $groupClassPage, $familyPage, $accountPage ) )->register();
|
|
}
|
|
}
|