announcements.install

  1. 6.x modules/announcements/announcements.install
  2. 4.x modules/announcements/announcements.install
  3. 5.x modules/announcements/announcements.install

File

modules/announcements/announcements.install
View source
  1. <?php
  2. /**
  3. * This file should contain only hooks relating to installing, enabling, disabling, and uninstalling this module.
  4. *
  5. */
  6. /**
  7. * Hook install. Called when the module is installed on the admin modules page.
  8. *
  9. */
  10. function announcements_install() {
  11. // Install our table
  12. $q = "
  13. CREATE TABLE `content__announcement` (
  14. `cid` int unsigned NOT NULL,
  15. `vid` int NOT NULL,
  16. `field__activity_datetime` datetime DEFAULT NULL,
  17. `field__msg` longtext,
  18. `field__visibility` varchar(255) DEFAULT NULL,
  19. PRIMARY KEY (`vid`),
  20. KEY `cid` (`cid`),
  21. KEY `visibility` (`field__visibility`),
  22. KEY `field__activity_datetime` (`field__activity_datetime`)
  23. );
  24. ";
  25. db_query($q);
  26. }
  27. function announcements_update($old_schema, $new_schema) {
  28. if (intval($old_schema) < 2) {
  29. // Convert text fields to longtext.
  30. db_query("ALTER TABLE content__announcement MODIFY field__msg LONGTEXT");
  31. fpm("Altered content__announcement table to change 'field__msg' to LONGTEXT.");
  32. }
  33. }
  34. function announcements_enable() {
  35. // Now, add a piece of custom content using content_save() function.
  36. $content = new stdClass();
  37. $content->type = 'announcement';
  38. $content->cid = "new";
  39. $content->published = 1;
  40. $content->delete_flag = 0;
  41. $content->title = "Sample Announcement";
  42. // TODO: This extra field data (aside from title) is not getting saved on first install, because hooks do not appear to be working
  43. // on first install of FlightPath. At least, not in this situation. I think it's because the content_content_save function cannot find
  44. // all the fields associated with this content type.
  45. $content->field__activity_datetime['value'] = date("Y-m-d H:ia");
  46. $content->field__msg['value'] = '<p>This is a sample announcement! You may add new announcements (or delete this one) from the Admin Tools, then Content.</p>';
  47. $content->field__visibility['value'] = 'public';
  48. content_content_save($content); // Since this is in our install script (which is run on first installation of FlightPath, we will call content_content_save, instead
  49. // of just content_save, thereby skipping the hook check.
  50. }

Functions

Namesort descending Description
announcements_enable
announcements_install Hook install. Called when the module is installed on the admin modules page.
announcements_update