Usage_stats.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * GNU social - a federating social network
  4. *
  5. * LICENCE: This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. if (!defined('GNUSOCIAL')) {
  19. exit(1);
  20. }
  21. /**
  22. * Table Definition for Usage_stats
  23. */
  24. class Usage_stats extends Managed_DataObject
  25. {
  26. ###START_AUTOCODE
  27. /* the code below is auto generated do not remove the above tag */
  28. public $__table = 'usage_stats'; // table name
  29. public $type; // varchar(191) unique_key not 255 because utf8mb4 takes more space
  30. public $count; // int(4)
  31. public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
  32. /* the code above is auto generated do not remove the tag below */
  33. ###END_AUTOCODE
  34. public static function schemaDef()
  35. {
  36. return [
  37. 'description' => 'node stats',
  38. 'fields' => [
  39. 'type' => ['type' => 'varchar', 'length' => 191, 'description' => 'Type of countable entity'],
  40. 'count' => ['type' => 'int', 'size' => 'int', 'default' => 0, 'description' => 'Number of entities of this type'],
  41. 'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'],
  42. ],
  43. 'primary key' => ['type'],
  44. 'unique keys' => [
  45. 'usage_stats_key' => ['type'],
  46. ],
  47. 'indexes' => [
  48. 'user_stats_idx' => ['type'],
  49. ],
  50. ];
  51. }
  52. public function getUserCount()
  53. {
  54. return intval(Usage_stats::getKV('type', 'users')->count);
  55. }
  56. public function getPostCount()
  57. {
  58. return intval(Usage_stats::getKV('type', 'posts')->count);
  59. }
  60. public function getCommentCount()
  61. {
  62. return intval(Usage_stats::getKV('type', 'comments')->count);
  63. }
  64. }