/system/expressionengine/modules/metaweblog_api/upd.metaweblog_api.php

https://bitbucket.org/mbaily/tremain · PHP · 217 lines · 139 code · 32 blank · 46 comment · 5 complexity · 2c8744a41b822dbbfc2d386be9b5707e MD5 · raw file

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * ExpressionEngine - by EllisLab
  4. *
  5. * @package ExpressionEngine
  6. * @author EllisLab Dev Team
  7. * @copyright Copyright (c) 2003 - 2013, EllisLab, Inc.
  8. * @license http://ellislab.com/expressionengine/user-guide/license.html
  9. * @link http://ellislab.com
  10. * @since Version 2.0
  11. * @filesource
  12. */
  13. // ------------------------------------------------------------------------
  14. /**
  15. * ExpressionEngine Metaweblog API Module
  16. *
  17. * @package ExpressionEngine
  18. * @subpackage Modules
  19. * @category Update File
  20. * @author EllisLab Dev Team
  21. * @link http://ellislab.com
  22. */
  23. class Metaweblog_api_upd {
  24. var $version = '2.1';
  25. function Metaweblog_api_upd()
  26. {
  27. // Make a local reference to the ExpressionEngine super object
  28. $this->EE =& get_instance();
  29. ee()->load->dbforge();
  30. }
  31. // --------------------------------------------------------------------
  32. /**
  33. * Module Installer
  34. *
  35. * @access public
  36. * @return bool
  37. */
  38. function install()
  39. {
  40. $data = array(
  41. 'module_name' => 'Metaweblog_api',
  42. 'module_version' => $this->version,
  43. 'has_cp_backend' => 'y'
  44. );
  45. ee()->db->insert('modules', $data);
  46. $data = array(
  47. 'class' => 'Metaweblog_api',
  48. 'method' => 'incoming'
  49. );
  50. ee()->db->insert('actions', $data);
  51. $fields = array(
  52. 'metaweblog_id' => array(
  53. 'type' => 'int',
  54. 'constraint' => 5,
  55. 'unsigned' => TRUE,
  56. 'null' => FALSE,
  57. 'auto_increment' => TRUE
  58. ),
  59. 'metaweblog_pref_name' => array(
  60. 'type' => 'varchar',
  61. 'constraint' => '80',
  62. 'null' => FALSE,
  63. 'default' => ''
  64. ),
  65. 'metaweblog_parse_type' => array(
  66. 'type' => 'varchar',
  67. 'constraint' => '1',
  68. 'null' => FALSE,
  69. 'default' => 'y'
  70. ),
  71. 'entry_status' => array(
  72. 'type' => 'varchar',
  73. 'constraint' => '50',
  74. 'null' => FALSE,
  75. 'default' => 'NULL'
  76. ),
  77. 'field_group_id' => array(
  78. 'type' => 'int',
  79. 'constraint' => '5',
  80. 'unsigned' => TRUE,
  81. 'null' => FALSE,
  82. 'default' => 0
  83. ),
  84. 'excerpt_field_id' => array(
  85. 'type' => 'int',
  86. 'constraint' => 7,
  87. 'unsigned' => TRUE,
  88. 'null' => FALSE,
  89. 'default' => 0
  90. ),
  91. 'content_field_id' => array(
  92. 'type' => 'int',
  93. 'constraint' => 7,
  94. 'unsigned' => TRUE,
  95. 'null' => FALSE,
  96. 'default' => 0
  97. ),
  98. 'more_field_id' => array(
  99. 'type' => 'int',
  100. 'constraint' => 7,
  101. 'unsigned' => TRUE,
  102. 'null' => FALSE,
  103. 'default' => 0
  104. ),
  105. 'keywords_field_id' => array(
  106. 'type' => 'int',
  107. 'constraint' => 7,
  108. 'unsigned' => TRUE,
  109. 'null' => FALSE,
  110. 'default' => 0
  111. ),
  112. 'upload_dir' => array(
  113. 'type' => 'int',
  114. 'constraint' => 5,
  115. 'unsigned' => TRUE,
  116. 'null' => FALSE,
  117. 'default' => 1
  118. ),
  119. );
  120. ee()->dbforge->add_field($fields);
  121. ee()->dbforge->add_key('metaweblog_id', TRUE);
  122. ee()->dbforge->create_table('metaweblog_api', TRUE);
  123. $data = array(
  124. 'metaweblog_pref_name' => 'Default',
  125. 'field_group_id' => 1,
  126. 'content_field_id' => 2
  127. );
  128. ee()->db->insert('metaweblog_api', $data);
  129. return TRUE;
  130. }
  131. // --------------------------------------------------------------------
  132. /**
  133. * Module Uninstaller
  134. *
  135. * @access public
  136. * @return bool
  137. */
  138. function uninstall()
  139. {
  140. ee()->db->select('module_id');
  141. $query = ee()->db->get_where('modules', array('module_name' => 'Metaweblog_api'));
  142. ee()->db->where('module_id', $query->row('module_id'));
  143. ee()->db->delete('module_member_groups');
  144. ee()->db->where('module_name', 'Metaweblog_api');
  145. ee()->db->delete('modules');
  146. ee()->db->where('class', 'Metaweblog_api');
  147. ee()->db->delete('actions');
  148. ee()->dbforge->drop_table('metaweblog_api');
  149. return TRUE;
  150. }
  151. // --------------------------------------------------------------------
  152. /**
  153. * Module Updater
  154. *
  155. * @access public
  156. * @return bool
  157. */
  158. function update($version = '')
  159. {
  160. if (version_compare($version, '2', '<') && ee()->db->table_exists('exp_metaweblog_api'))
  161. {
  162. $existing_fields = array();
  163. $new_fields = array('entry_status' => "`entry_status` varchar(50) NOT NULL default 'null' AFTER `metaweblog_parse_type`");
  164. $query = ee()->db->query("SHOW COLUMNS FROM exp_metaweblog_api");
  165. foreach($query->result_array() as $row)
  166. {
  167. $existing_fields[] = $row['Field'];
  168. }
  169. foreach($new_fields as $field => $alter)
  170. {
  171. if ( ! in_array($field, $existing_fields))
  172. {
  173. ee()->db->query("ALTER table exp_metaweblog_api ADD COLUMN {$alter}");
  174. }
  175. }
  176. }
  177. if (version_compare($version, '2.1', '<'))
  178. {
  179. // nothing to see here!
  180. }
  181. return TRUE;
  182. }
  183. }
  184. /* End of file upd.metaweblog_api.php */
  185. /* Location: ./system/expressionengine/modules/metaweblog_api/upd.metaweblog_api.php */