Commit 1f779bdd authored by Aaron Wells's avatar Aaron Wells

Make Collection::save() play well with existing collections & non-null columns

Bug 1381811: Collection::save() would create a new (empty) collection by
passing 0 as the id to the Collection constructor, even if the supplied
$data included an "id" field. Since the id was not supplied to the
constructor, it does not pull the collection's current data from the

It would then call Collection->commit(), which would notice the "id"
field and do an update instead of an insert into the database. But due to
the way the Collection class is written, it would try to populate every
field of the collection table, rather than just those supplied in $data.

This means that all the database fields not supplied in $data, would
attempt to be filled with NULL. This threw an error because of the new
collection.submittedstatus NOT-NULL column.

Change-Id: I6a2927892459bd25d51bd58de1bd3e3584df0793
parent f36fbc1c
......@@ -90,13 +90,19 @@ class Collection {
* Creates a new Collection for the given user.
* Helper function to create or update a Collection from the supplied data.
* @param array $data
* @return collection The newly created Collection
* @return collection The newly created/updated collection
public static function save($data) {
$collection = new Collection(0, $data);
if (array_key_exists('id', $data)) {
$id = $data['id'];
else {
$id = 0;
$collection = new Collection($id, $data);
return $collection; // return newly created Collections id
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment