/**
  * Increment a user's greeting count and return instance
  *
  * This method handles the ins and outs of creating a new greeting_count for a
  * user or fetching the existing greeting count and incrementing its value.
  *
  * @param integer $user_id ID of the user to get a count for
  *
  * @return User_greeting_count instance for this user, with count already incremented.
  */
 static function inc($user_id)
 {
     $gc = User_greeting_count::getKV('user_id', $user_id);
     if (empty($gc)) {
         $gc = new User_greeting_count();
         $gc->user_id = $user_id;
         $gc->greeting_count = 1;
         $result = $gc->insert();
         if (!$result) {
             // TRANS: Exception thrown when the user greeting count could not be saved in the database.
             // TRANS: %d is a user ID (number).
             throw new Exception(sprintf(_m('Could not save new greeting count for %d.'), $user_id));
         }
     } else {
         $orig = clone $gc;
         $gc->greeting_count++;
         $result = $gc->update($orig);
         if (!$result) {
             // TRANS: Exception thrown when the user greeting count could not be saved in the database.
             // TRANS: %d is a user ID (number).
             throw new Exception(sprintf(_m('Could not increment greeting count for %d.'), $user_id));
         }
     }
     return $gc;
 }
Example #2
0
 /**
  * Take arguments for running
  *
  * This method is called first, and it lets the action class get
  * all its arguments and validate them. It's also the time
  * to fetch any relevant data from the database.
  *
  * Action classes should run parent::prepare($args) as the first
  * line of this method to make sure the default argument-processing
  * happens.
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     $this->user = common_current_user();
     if (!empty($this->user)) {
         $this->gc = User_greeting_count::inc($this->user->id);
     }
     return true;
 }
Example #3
0
 /**
  * Increment a user's greeting count and return instance
  *
  * This method handles the ins and outs of creating a new greeting_count for a
  * user or fetching the existing greeting count and incrementing its value.
  *
  * @param integer $user_id ID of the user to get a count for
  *
  * @return User_greeting_count instance for this user, with count already incremented.
  */
 static function inc($user_id)
 {
     $gc = User_greeting_count::staticGet('user_id', $user_id);
     if (empty($gc)) {
         $gc = new User_greeting_count();
         $gc->user_id = $user_id;
         $gc->greeting_count = 1;
         $result = $gc->insert();
         if (!$result) {
             throw Exception(sprintf(_m("Could not save new greeting count for %d"), $user_id));
         }
     } else {
         $orig = clone $gc;
         $gc->greeting_count++;
         $result = $gc->update($orig);
         if (!$result) {
             throw Exception(sprintf(_m("Could not increment greeting count for %d"), $user_id));
         }
     }
     return $gc;
 }
Example #4
0
 /**
  * Database schema setup
  *
  * Plugins can add their own tables to the StatusNet database. Plugins
  * should use StatusNet's schema interface to add or delete tables. The
  * ensureTable() method provides an easy way to ensure a table's structure
  * and availability.
  *
  * By default, the schema is checked every time StatusNet is run (say, when
  * a Web page is hit). Admins can configure their systems to only check the
  * schema when the checkschema.php script is run, greatly improving performance.
  * However, they need to remember to run that script after installing or
  * upgrading a plugin!
  *
  * @see Schema
  * @see ColumnDef
  *
  * @return boolean hook value; true means continue processing, false means stop.
  */
 function onCheckSchema()
 {
     $schema = Schema::get();
     // For storing user-submitted flags on profiles
     $schema->ensureTable('user_greeting_count', User_greeting_count::schemaDef());
     return true;
 }