fontyourface.install 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <?php
  2. /**
  3. * @file
  4. * Adds fontyourface tables for tracking fonts.
  5. */
  6. /**
  7. * Re-usable function for the 7.2 schema.
  8. */
  9. function fontyourface_7200_schema() {
  10. $schema = array();
  11. $schema['fontyourface_font'] = array(
  12. 'description' => 'Font information.',
  13. 'fields' => array(
  14. 'fid' => array(
  15. 'type' => 'serial',
  16. 'unsigned' => TRUE,
  17. 'not null' => TRUE,
  18. 'description' => 'Primary Key: Unique font ID.',
  19. ),
  20. 'name' => array(
  21. 'type' => 'varchar',
  22. 'length' => 255,
  23. 'not null' => TRUE,
  24. 'default' => '',
  25. 'description' => 'The font name.',
  26. ),
  27. 'enabled' => array(
  28. 'type' => 'int',
  29. 'unsigned' => TRUE,
  30. 'not null' => TRUE,
  31. 'default' => 0,
  32. 'size' => 'tiny',
  33. 'description' => 'Whether or not the font is enabled. (0 = disabled, 1 = enabled)',
  34. ),
  35. 'url' => array(
  36. 'type' => 'varchar',
  37. 'length' => 255,
  38. 'not null' => TRUE,
  39. 'default' => '',
  40. 'description' => 'A URL for the font.',
  41. ),
  42. 'provider' => array(
  43. 'type' => 'varchar',
  44. 'length' => 255,
  45. 'not null' => TRUE,
  46. 'default' => '',
  47. 'description' => 'The module providing the font.',
  48. ),
  49. 'css_selector' => array(
  50. 'type' => 'text',
  51. 'not null' => FALSE,
  52. 'size' => 'big',
  53. 'description' => 'CSS selector for applying the font.',
  54. ),
  55. 'css_family' => array(
  56. 'type' => 'varchar',
  57. 'length' => 255,
  58. 'not null' => FALSE,
  59. 'default' => '',
  60. 'description' => 'CSS family for the font.',
  61. ),
  62. 'css_style' => array(
  63. 'type' => 'varchar',
  64. 'length' => 255,
  65. 'not null' => FALSE,
  66. 'default' => '',
  67. 'description' => 'CSS style for the font.',
  68. ),
  69. 'css_weight' => array(
  70. 'type' => 'varchar',
  71. 'length' => 255,
  72. 'not null' => FALSE,
  73. 'default' => '',
  74. 'description' => 'CSS weight for the font.',
  75. ),
  76. 'css_fallbacks' => array(
  77. 'type' => 'varchar',
  78. 'length' => 255,
  79. 'not null' => FALSE,
  80. 'default' => '',
  81. 'description' => 'CSS fallbacks for the font.',
  82. ),
  83. 'foundry' => array(
  84. 'type' => 'varchar',
  85. 'length' => 255,
  86. 'not null' => FALSE,
  87. 'default' => '',
  88. 'description' => 'Foundry for the font.',
  89. ),
  90. 'foundry_url' => array(
  91. 'type' => 'varchar',
  92. 'length' => 255,
  93. 'not null' => FALSE,
  94. 'default' => '',
  95. 'description' => 'URL for foundry for the font.',
  96. ),
  97. 'license' => array(
  98. 'type' => 'varchar',
  99. 'length' => 255,
  100. 'not null' => FALSE,
  101. 'default' => '',
  102. 'description' => 'License for the font.',
  103. ),
  104. 'license_url' => array(
  105. 'type' => 'varchar',
  106. 'length' => 255,
  107. 'not null' => FALSE,
  108. 'default' => '',
  109. 'description' => 'URL for license for the font.',
  110. ),
  111. 'designer' => array(
  112. 'type' => 'varchar',
  113. 'length' => 255,
  114. 'not null' => FALSE,
  115. 'default' => '',
  116. 'description' => 'Designer for the font.',
  117. ),
  118. 'designer_url' => array(
  119. 'type' => 'varchar',
  120. 'length' => 255,
  121. 'not null' => FALSE,
  122. 'default' => '',
  123. 'description' => 'URL for designer for the font.',
  124. ),
  125. 'metadata' => array(
  126. 'type' => 'text',
  127. 'not null' => FALSE,
  128. 'size' => 'big',
  129. 'description' => 'Additional serialized metadata about the font.',
  130. ),
  131. ),
  132. 'indexes' => array(
  133. 'enabled' => array('enabled'),
  134. ),
  135. 'unique keys' => array(
  136. 'url' => array('url'),
  137. ),
  138. 'primary key' => array('fid'),
  139. );
  140. $schema['fontyourface_tag'] = array(
  141. 'description' => 'Font tag information.',
  142. 'fields' => array(
  143. 'tid' => array(
  144. 'type' => 'serial',
  145. 'unsigned' => TRUE,
  146. 'not null' => TRUE,
  147. 'description' => 'Primary Key: Unique tag ID.',
  148. ),
  149. 'name' => array(
  150. 'type' => 'varchar',
  151. 'length' => 255,
  152. 'not null' => TRUE,
  153. 'default' => '',
  154. 'description' => 'The font name.',
  155. ),
  156. 'type' => array(
  157. 'type' => 'varchar',
  158. 'length' => 10,
  159. 'not null' => TRUE,
  160. 'default' => 'tag',
  161. 'description' => 'Indicator that describes the type of tag (term, subset, etc).',
  162. ),
  163. ),
  164. 'primary key' => array('tid'),
  165. );
  166. $schema['fontyourface_tag_font'] = array(
  167. 'description' => 'Relationship information between fonts and tags.',
  168. 'fields' => array(
  169. 'fid' => array(
  170. 'type' => 'int',
  171. 'unsigned' => TRUE,
  172. 'not null' => TRUE,
  173. 'default' => 0,
  174. 'description' => 'Foreign Key: the unique ID of the font.',
  175. ),
  176. 'tid' => array(
  177. 'type' => 'int',
  178. 'unsigned' => TRUE,
  179. 'not null' => TRUE,
  180. 'default' => 0,
  181. 'description' => 'Foreign Key: the unique ID of the tag.',
  182. ),
  183. ),
  184. 'indexes' => array(
  185. 'fid' => array('fid'),
  186. 'tid' => array('tid'),
  187. ),
  188. 'primary key' => array('fid', 'tid'),
  189. );
  190. return $schema;
  191. } // fontyourface_7200_schema
  192. /**
  193. * Implements hook_schema().
  194. */
  195. function fontyourface_schema() {
  196. return fontyourface_7200_schema();
  197. } // fontyourface_schema
  198. /**
  199. * Moves admin interface to fontyourface_ui module.
  200. */
  201. function fontyourface_update_7200() {
  202. // Move UI over to new fontyourface_ui module.
  203. module_enable(array('fontyourface_ui'));
  204. views_invalidate_cache();
  205. // Add new fields to schema.
  206. $schema = fontyourface_7200_schema();
  207. db_add_field('fontyourface_font', 'css_fallbacks', $schema['fontyourface_font']['fields']['css_fallbacks']);
  208. db_add_field('fontyourface_font', 'designer', $schema['fontyourface_font']['fields']['designer']);
  209. db_add_field('fontyourface_font', 'designer_url', $schema['fontyourface_font']['fields']['designer_url']);
  210. } // fontyourface_update_7200
  211. /**
  212. * Distinct subsets from tags using an extra 'type' column.
  213. */
  214. function fontyourface_update_7201() {
  215. views_invalidate_cache();
  216. // Add new column to schema.
  217. $schema = fontyourface_7200_schema();
  218. db_add_field('fontyourface_tag', 'type', $schema['fontyourface_tag']['fields']['type']);
  219. // Convert existing Google Fonts tags to subsets
  220. $query = db_select('fontyourface_tag', 't');
  221. $query->innerJoin('fontyourface_tag_font', 'tf', 'tf.tid = t.tid');
  222. $query->innerJoin('fontyourface_font', 'f', 'f.fid = tf.fid');
  223. $query->distinct();
  224. $result = $query->fields('t', array('tid'))
  225. ->condition('f.provider', 'google_fonts_api')
  226. ->execute();
  227. foreach ($result as $font) {
  228. db_update('fontyourface_tag')
  229. ->fields(array('type' => 'subset'))
  230. ->condition('tid', $font->tid)
  231. ->execute();
  232. } // foreach
  233. } // fontyourface_update_7201
  234. /**
  235. * Make the 'url' column unique to enable exportables
  236. */
  237. function fontyourface_update_7202() {
  238. $schema = fontyourface_7200_schema();
  239. try {
  240. db_add_unique_key('fontyourface_font', 'url', array('url'));
  241. }
  242. catch (DatabaseSchemaObjectExistsException $e) {
  243. // Fail silently.
  244. }
  245. } // fontyourface_update_7202
  246. /**
  247. * Remove single quotes from CSS selectors
  248. */
  249. function fontyourface_update_7203() {
  250. // Removed - this will not work on SQLite databases.
  251. //db_query("UPDATE {fontyourface_font} SET css_family = REPLACE(css_family, '\'', '');");
  252. } // fontyourface_update_7203
  253. /**
  254. * Remove single quotes from CSS selectors - properly this time.
  255. */
  256. function fontyourface_update_7204() {
  257. db_update('fontyourface_font')
  258. ->expression('css_family', "REPLACE(css_family, '''', '')")
  259. ->execute();
  260. }
  261. /**
  262. * Implements hook_uninstall().
  263. */
  264. function fontyourface_uninstall() {
  265. variable_del('fontyourface_short_preview_text');
  266. variable_del('fontyourface_detailed_logging');
  267. variable_del('fontyourface_css_md5');
  268. } // fontyourface_uninstall