Millores a utils/add_subjects.php
Ara es permet elidir la propietat friendly_name, i es fa que si el
calendar_name està en majúscules es transformi tot en minúscules, perquè
funcioni la comparació a la BD (l'script de Python afegeix les classes
amb un calendar_name tot en minúscules).
Change-Id: Ic0fb2179e93ea26cef83e5992a8f1030a630fbb7
diff --git a/utils/add_subjects.php b/utils/add_subjects.php
index 9c6b9ee..00a8039 100644
--- a/utils/add_subjects.php
+++ b/utils/add_subjects.php
@@ -27,12 +27,17 @@
$query = $con->prepare('INSERT INTO subjects (friendly_name, calendar_name) VALUES (:friendly_name, :calendar_name)');
foreach ($subjects as $subject) {
- if (!isset($subject['friendly_name']) || !isset($subject['calendar_name']) || empty($subject['friendly_name']) || empty($subject['calendar_name'])) {
+ if (!isset($subject['calendar_name']) || empty($subject['calendar_name'])) {
$con->rollback();
- echo "The JSON file passed is malformed. It should be an array consisting of objects which have non-empty 'friendly_name' and 'calendar_name' properties.\n";
+ echo "The JSON file passed is malformed. It should be an array consisting of objects which have a non-empty 'calendar_name' property and optionally a 'friendly_name' property.\n";
exit();
}
+ if (!isset($subject['friendly_name']) || empty($subject['friendly_name']))
+ $subject['friendly_name'] = $subject['calendar_name'];
+
+ $subject['calendar_name'] = mb_strtolower($subject['calendar_name']);
+
if (!$query->execute($subject)) {
echo "An error occurred while adding the subject '".$subject['friendly_name']."' to the database. This doesn't affect the other subjects.\n";
}