/** * @brief inserts a new user or group into the mappings table * @param $dn the record in question * @param $ocname the name to use in ownCloud * @param $isUser is it a user or a group? * @returns true on success, false otherwise * * inserts a new user or group into the mappings table */ private static function mapComponent($dn, $ocname, $isUser = true) { $table = self::getMapTable($isUser); $dn = self::sanitizeDN($dn); $sqlAdjustment = ''; $dbtype = OCP\Config::getSystemValue('dbtype'); if ($dbtype == 'mysql') { $sqlAdjustment = 'FROM dual'; } $insert = OCP\DB::prepare(' INSERT INTO ' . $table . ' (ldap_dn, owncloud_name) SELECT ?,? ' . $sqlAdjustment . ' WHERE NOT EXISTS ( SELECT 1 FROM ' . $table . ' WHERE ldap_dn = ? OR owncloud_name = ? ) '); $res = $insert->execute(array($dn, $ocname, $dn, $ocname)); if (OCP\DB::isError($res)) { return false; } $insRows = $res->numRows(); if ($insRows == 0) { return false; } return true; }
/** * Add an album to the database * @param string name * @param integer artist * @return integer the album_id of the added artist */ public static function addAlbum($name, $artist) { $name = trim($name); if ($name == '') { return 0; } //check if the album is already in the database $albumId = self::getAlbumId($name, $artist); if ($albumId != 0) { return $albumId; } else { $stmt = OCP\DB::prepare('INSERT INTO `*PREFIX*media_albums` (`album_name` ,`album_artist`) VALUES ( ?, ?)'); if (!OCP\DB::isError($stmt)) { $result = $stmt->execute(array($name, $artist)); if (OCP\DB::isError($result)) { OC_Log::write('OC_MEDIA_COLLECTION', 'could not add album: ' . OC_DB::getErrorMessage($result), OC_Log::ERROR); } } else { OC_Log::write('OC_MEDIA_COLLECTION', 'could not add album: ' . OC_DB::getErrorMessage($stmt), OC_Log::ERROR); } return self::getAlbumId($name, $artist); } }