/** * @param Storage $storage * @return void * * @throws CouldNotAddStorage */ public function add(Storage $storage) { $query = $this->db->prepareQuery('INSERT INTO *PREFIX*uc_storageusage (created, username, `usage`, maximumusage) VALUES (?,?,?,?)'); $result = $query->execute([$storage->dateTime()->format('Y-m-d H:i:s'), $storage->user()->name(), $storage->bytes()->numberOfBytes(), $storage->quota()->bytes()->numberOfBytes()]); /* * $query->execute could return integer or OC_DB_StatementWrapper or false * I am expecting an integer with number 1 */ if (!is_int($result) || $result !== 1) { throw CouldNotAddStorage::byStorage($storage); } }
/** * @param Storage $storage * @return CouldNotAddStorage */ public static function byStorage(Storage $storage) { return new self("Could not add storage for " . $storage->user()->name()); }