php js css php js css

Changes

Changes to Script: Use realistic course codes and fictional contact names

246117
Today 4:33am
McNaught, Scott
Modified script
246118
Today 4:33am
McNaught, Scott
Modified script
Modified:
Id:
1jRXW8Okr33laQdj
1jRXW8Okr33laQdj
Title:
Use realistic course codes and fictional contact names
Use realistic course codes and fictional contact names
Code:
<?php
$courseCodes = [376 => 'A1.1-FRI-20261009', 377 => 'A1.1-WED-20261007', 378 => 'PT-A1-2026-0378'];
$names = [1393 => ['Camille', 'Laurent'], 1394 => ['Alex', 'Bennett'], 1395 => ['Sophie', 'Martin'], 1396 => ['Jordan', 'Ellis'], 1397 => ['Morgan', 'Taylor'], 1398 => ['Robin', 'Moreau']];
foreach ($courseCodes as $id => $code) {
$matches = \Components\AF\Courses::getAll(['filter' => [['course_code', '=', $code], 'AND', ['course_id', '!=', $id]], 'limit' => 1]);
if ($matches) throw new \RuntimeException('Course code already in use: ' . $code);
}
foreach ($names as $id => $name) {
$email = strtolower($name[0] . '.' . $name[1]) . '@example.invalid';
$matches = \Components\Customers\Contacts::getAll(['filter' => [['contact_email', '=', $email], 'AND', ['contact_id', '!=', $id]], 'limit' => 1]);
if ($matches) throw new \RuntimeException('Contact email already in use.');
}
$disabledBefore = \Components\Marketing\Automation\Progress::getDisabledIds();
\Components\Marketing\Automation\Progress::setDisabledIds(array_column(\Components\Marketing\Automation::getAll(), 'automation_id'));
try {
foreach ($names as $id => $name) {
\Components\Customers\Contacts::save(['contact_id' => $id, 'contact_first_name' => $name[0], 'contact_last_name' => $name[1], 'contact_email' => strtolower($name[0] . '.' . $name[1]) . '@example.invalid']);
}
foreach ($courseCodes as $id => $code) {
$course = \Components\AF\Courses::get($id);
$update = array_intersect_key($course, array_flip(['course_id', 'course_type', 'product_id', 'age_group_id', 'session_id', 'type_id', 'pace_id']));
\Components\AF\Courses::save(array_replace($update, ['course_code' => $code]));
}
$out = ['courses' => [], 'contacts' => [], 'private_total_hours' => \Components\AF\Courses\Hours::getTotalForCourse(378)];
foreach ($courseCodes as $id => $expected) {
$course = \Components\AF\Courses::get($id);
if ($course['course_code'] !== $expected) throw new \RuntimeException('Course code was not saved.');
$out['courses'][] = ['id' => $id, 'code' => $course['course_code'], 'type' => $course['course_type'], 'online_reasons' => $course['course_type'] === 'collective' ? \Components\AF\Courses::getCourseNotVisibleReasons($course) : null];
}
foreach ($names as $id => $name) {
$contact = \Components\Customers\Contacts::get($id);
if ($contact['contact_first_name'] !== $name[0] || $contact['contact_last_name'] !== $name[1]) throw new \RuntimeException('Contact name was not saved.');
$out['contacts'][] = ['id' => $id, 'name' => $contact['contact_first_name'] . ' ' . $contact['contact_last_name'], 'email' => $contact['contact_email']];
}
echo json_encode($out, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
} finally {
\Components\Marketing\Automation\Progress::setDisabledIds($disabledBefore);
}
<?php
$courseCodes = [376 => 'A1.1-FRI-20261009', 377 => 'A1.1-WED-20261007', 378 => 'PT-A1-2026-0378'];
$names = [1393 => ['Camille', 'Laurent'], 1394 => ['Alex', 'Bennett'], 1395 => ['Sophie', 'Martin'], 1396 => ['Jordan', 'Ellis'], 1397 => ['Morgan', 'Taylor'], 1398 => ['Robin', 'Moreau']];
foreach ($courseCodes as $id => $code) {
$matches = \Components\AF\Courses::getAll(['filter' => [['course_code', '=', $code], 'AND', ['course_id', '!=', $id]], 'limit' => 1]);
if ($matches) throw new \RuntimeException('Course code already in use: ' . $code);
}
foreach ($names as $id => $name) {
$email = strtolower($name[0] . '.' . $name[1]) . '@example.invalid';
$matches = \Components\Customers\Contacts::getAll(['filter' => [['contact_email', '=', $email], 'AND', ['contact_id', '!=', $id]], 'limit' => 1]);
if ($matches) throw new \RuntimeException('Contact email already in use.');
}
$disabledBefore = \Components\Marketing\Automation\Progress::getDisabledIds();
\Components\Marketing\Automation\Progress::setDisabledIds(array_column(\Components\Marketing\Automation::getAll(), 'automation_id'));
try {
foreach ($names as $id => $name) {
\Components\Customers\Contacts::save(['contact_id' => $id, 'contact_first_name' => $name[0], 'contact_last_name' => $name[1], 'contact_email' => strtolower($name[0] . '.' . $name[1]) . '@example.invalid']);
}
foreach ($courseCodes as $id => $code) {
$course = \Components\AF\Courses::get($id);
$update = array_intersect_key($course, array_flip(['course_id', 'course_type', 'product_id', 'age_group_id', 'session_id', 'type_id', 'pace_id']));
\Components\AF\Courses::save(array_replace($update, ['course_code' => $code]));
}
$out = ['courses' => [], 'contacts' => [], 'private_total_hours' => \Components\AF\Courses\Hours::getTotalForCourse(378)];
foreach ($courseCodes as $id => $expected) {
$course = \Components\AF\Courses::get($id);
if ($course['course_code'] !== $expected) throw new \RuntimeException('Course code was not saved.');
$out['courses'][] = ['id' => $id, 'code' => $course['course_code'], 'type' => $course['course_type'], 'online_reasons' => $course['course_type'] === 'collective' ? \Components\AF\Courses::getCourseNotVisibleReasons($course) : null];
}
foreach ($names as $id => $name) {
$contact = \Components\Customers\Contacts::get($id);
if ($contact['contact_first_name'] !== $name[0] || $contact['contact_last_name'] !== $name[1]) throw new \RuntimeException('Contact name was not saved.');
$out['contacts'][] = ['id' => $id, 'name' => $contact['contact_first_name'] . ' ' . $contact['contact_last_name'], 'email' => $contact['contact_email']];
}
echo json_encode($out, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
} finally {
\Components\Marketing\Automation\Progress::setDisabledIds($disabledBefore);
}
Last Run:

															

														
Created:
2026-10-08 01:19:45
2026-10-08 01:19:45
Is Ai Generated:
Is Readonly:
Summary:
This script makes changes to your customer and course records, then shows a summary of what was changed. Here's what it does, step by step:

**Safety checks first (nothing is changed yet):**
- It checks that three course codes (A1.1-FRI-20261009, A1.1-WED-20261007, and PT-A1-2026-0378) aren't already being used by any *other* course. If any of them is, it stops and changes nothing.
- It checks that six email addresses (like camille.laurent@example.invalid) aren't already used by any *other* customer contact. If any is, it stops and changes nothing.

**Temporary setting:**
- It briefly turns off all automated marketing messages so that nothing gets triggered while it works. It turns this back on at the end, even if something goes wrong.

**Changes it makes:**
- **6 customer contacts** (Camille Laurent, Alex Bennett, Sophie Martin, Jordan Ellis, Morgan Taylor, Robin Moreau): each one gets their first name, last name, and a new email address (firstname.lastname@example.invalid) written into their record.
- **3 courses**: each one gets its course code replaced with one of the three new codes listed above. Everything else about the course (type, product, age group, etc.) stays the same.

**After the changes:**
- It re-reads each of the 6 contacts and 3 courses to confirm the new names, emails, and codes were actually saved. If anything didn't save, it stops with an error.
- It prints a summary showing the 3 courses (with their new codes and, for group courses, why they might not be visible online) and the 6 contacts (with their names and new emails), plus the total number of hours booked for the private course.

**In short:** it renames and re-emails 6 specific customer contacts and gives 3 specific courses new codes, with checks beforehand to make sure none of the new codes or emails are already taken by someone else.
This script makes changes to your customer and course records, then shows a summary of what was changed. Here's what it does, step by step:

**Safety checks first (nothing is changed yet):**
- It checks that three course codes (A1.1-FRI-20261009, A1.1-WED-20261007, and PT-A1-2026-0378) aren't already being used by any *other* course. If any of them is, it stops and changes nothing.
- It checks that six email addresses (like camille.laurent@example.invalid) aren't already used by any *other* customer contact. If any is, it stops and changes nothing.

**Temporary setting:**
- It briefly turns off all automated marketing messages so that nothing gets triggered while it works. It turns this back on at the end, even if something goes wrong.

**Changes it makes:**
- **6 customer contacts** (Camille Laurent, Alex Bennett, Sophie Martin, Jordan Ellis, Morgan Taylor, Robin Moreau): each one gets their first name, last name, and a new email address (firstname.lastname@example.invalid) written into their record.
- **3 courses**: each one gets its course code replaced with one of the three new codes listed above. Everything else about the course (type, product, age group, etc.) stays the same.

**After the changes:**
- It re-reads each of the 6 contacts and 3 courses to confirm the new names, emails, and codes were actually saved. If anything didn't save, it stops with an error.
- It prints a summary showing the 3 courses (with their new codes and, for group courses, why they might not be visible online) and the 6 contacts (with their names and new emails), plus the total number of hours booked for the private course.

**In short:** it renames and re-emails 6 specific customer contacts and gives 3 specific courses new codes, with checks beforehand to make sure none of the new codes or emails are already taken by someone else.
Contact Id:
-2
-2