@@ -290,4 +290,83 @@ public function refresh() {
290290 return false ;
291291 }
292292
293+ public function save () {
294+ if (!isset (Common::$ database )) {
295+ Common::$ database = DatabaseDriver::getDatabaseObject ();
296+ }
297+
298+ try {
299+
300+ $ stmt = Common::$ database ->prepare ('
301+ UPDATE
302+ `servers`
303+ SET
304+ `address` = :address,
305+ `created_datetime` = :created_dt,
306+ `label` = :label,
307+ `port` = :port,
308+ `status_bitmask` = :status,
309+ `type_id` = :type_id,
310+ `updated_datetime` = :updated_dt,
311+ `user_id` = :user_id
312+ WHERE
313+ `id` = :id
314+ LIMIT 1;
315+ ' );
316+
317+ $ stmt ->bindParam ( ':address ' , $ this ->address , PDO ::PARAM_STR );
318+ $ stmt ->bindParam (
319+ ':created_dt ' , $ this ->created_datetime , PDO ::PARAM_STR
320+ );
321+ $ stmt ->bindParam ( ':label ' , $ this ->label , PDO ::PARAM_STR );
322+ $ stmt ->bindParam ( ':id ' , $ this ->id , PDO ::PARAM_INT );
323+ $ stmt ->bindParam ( ':port ' , $ this ->port , PDO ::PARAM_INT );
324+ $ stmt ->bindParam ( ':status ' , $ this ->status_bitmask , PDO ::PARAM_INT );
325+ $ stmt ->bindParam ( ':type_id ' , $ this ->type_id , PDO ::PARAM_INT );
326+ if ( is_null ( $ this ->updated_datetime )) {
327+ $ stmt ->bindParam ( ':updated_dt ' , null , PDO ::PARAM_NULL );
328+ } else {
329+ $ stmt ->bindParam (
330+ ':updated_dt ' , $ this ->updated_datetime , PDO ::PARAM_STR
331+ );
332+ }
333+ if ( is_null ( $ this ->user_id )) {
334+ $ stmt ->bindParam ( ':user_id ' , null , PDO ::PARAM_NULL );
335+ } else {
336+ $ stmt ->bindParam ( ':user_id ' , $ this ->user_id , PDO ::PARAM_INT );
337+ }
338+
339+ if (!$ stmt ->execute ()) {
340+ throw new QueryException ( 'Cannot save server ' );
341+ }
342+ $ stmt ->closeCursor ();
343+
344+ $ object = new StdClass ();
345+ $ object ->address = $ this ->address ;
346+ $ object ->created_datetime = $ this ->created_datetime ;
347+ $ object ->id = $ this ->id ;
348+ $ object ->label = $ this ->label ;
349+ $ object ->port = $ this ->port ;
350+ $ object ->status_bitmask = $ this ->status_bitmask ;
351+ $ object ->type_id = $ this ->type_id ;
352+ $ object ->updated_datetime = $ this ->updated_datetime ;
353+ $ object ->user_id = $ this ->user_id ;
354+
355+ $ cache_key = 'bnetdocs-server- ' . $ this ->id ;
356+ Common::$ cache ->set ( $ cache_key , serialize ( $ object ), 300 );
357+ Common::$ cache ->delete ( 'bnetdocs-servers ' );
358+
359+ return true ;
360+
361+ } catch ( PDOException $ e ) {
362+ throw new QueryException ( 'Cannot save server ' , $ e );
363+ }
364+
365+ return false ;
366+ }
367+
368+ public function setStatusBitmask ( $ status_bitmask ) {
369+ $ this ->status_bitmask = $ status_bitmask ;
370+ }
371+
293372}
0 commit comments