| 1 |
<?php
|
| 2 |
|
| 3 |
// $Id: video_upload.install,v 1.6.2.5 2009/09/04 20:51:16 jhedstrom Exp $
|
| 4 |
|
| 5 |
/**
|
| 6 |
* @file
|
| 7 |
* Install/Uninstall/Enable/Disable hooks
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implement hook_install().
|
| 12 |
*/
|
| 13 |
function video_upload_install() {
|
| 14 |
drupal_set_message(t('Video Upload successfully installed, and can be configured <a href="!url">here</a>.', array('!url' => url('admin/settings/video-upload'))));
|
| 15 |
}
|
| 16 |
|
| 17 |
/**
|
| 18 |
* Implement hook_uninstall().
|
| 19 |
*/
|
| 20 |
function video_upload_uninstall() {
|
| 21 |
variable_del('video_upload_youtube_developer_key');
|
| 22 |
variable_del('video_upload_youtube_username');
|
| 23 |
variable_del('video_upload_youtube_password');
|
| 24 |
}
|
| 25 |
|
| 26 |
/**
|
| 27 |
* Implement hook_requirements().
|
| 28 |
*
|
| 29 |
* Checks for the existence required variable settings
|
| 30 |
*/
|
| 31 |
function video_upload_requirements($phase) {
|
| 32 |
|
| 33 |
$requirements = array();
|
| 34 |
|
| 35 |
// Ensure translations don't break at install time.
|
| 36 |
$t = get_t();
|
| 37 |
|
| 38 |
// Get GData-specific requirements.
|
| 39 |
// @todo: Once there is more than one provider, this can't be run at the
|
| 40 |
// install phase.
|
| 41 |
include_once drupal_get_path('module', 'video_upload') . '/video_upload.module';
|
| 42 |
video_upload_initialize_provider();
|
| 43 |
$gdata_requirements = _video_upload_gdata_requirements($phase);
|
| 44 |
|
| 45 |
if ($phase == 'runtime') {
|
| 46 |
|
| 47 |
$username = variable_get('video_upload_youtube_username', FALSE);
|
| 48 |
$password = variable_get('video_upload_youtube_password', FALSE);
|
| 49 |
$developer_key = variable_get('video_upload_youtube_developer_key', FALSE);
|
| 50 |
|
| 51 |
// Must have certain settings to use.
|
| 52 |
if (!$username) {
|
| 53 |
$requirements['video_upload_username'] = array(
|
| 54 |
'title' => $t('Video Upload: Username'),
|
| 55 |
'value' => $t('Not Found'),
|
| 56 |
'severity' => REQUIREMENT_ERROR,
|
| 57 |
'description' => $t('The Video Upload module requires at least one YouTube username/password combo, which can be set <a href="!url">here</a>.', array('!url' => url('admin/settings/video-upload'))),
|
| 58 |
);
|
| 59 |
}
|
| 60 |
if (!$password) {
|
| 61 |
$requirements['video_upload_password'] = array(
|
| 62 |
'title' => $t('Video Upload: Password'),
|
| 63 |
'value' => $t('Not Found'),
|
| 64 |
'severity' => REQUIREMENT_ERROR,
|
| 65 |
'description' => $t('The Video Upload module requires at least one YouTube username/password combo, which can be set <a href="!url">here</a>.', array('!url' => url('admin/settings/video-upload'))),
|
| 66 |
);
|
| 67 |
}
|
| 68 |
if (!$developer_key) {
|
| 69 |
$requirements['video_upload_developer_key'] = array(
|
| 70 |
'title' => $t('Video Upload: YouTube Developer Key'),
|
| 71 |
'value' => $t('Not Found'),
|
| 72 |
'severity' => REQUIREMENT_ERROR,
|
| 73 |
'description' => $t('The Video Upload module requires a <a href="!devurl">YouTube Developer Key</a>, which can be set <a href="!url">here</a>.', array('!url' => url('admin/settings/video-upload'), '!devurl' => url('http://code.google.com/apis/youtube/dashboard'))),
|
| 74 |
);
|
| 75 |
}
|
| 76 |
|
| 77 |
if ($username && $password && $developer_key && !_video_upload_authenticate_youtube()) {
|
| 78 |
// Failed to connect/authenticate.
|
| 79 |
$requirements['video_upload_authentication'] = array(
|
| 80 |
'title' => $t('Video Upload: YouTube Authentication'),
|
| 81 |
'value' => $t('Failed'),
|
| 82 |
'severity' => REQUIREMENT_ERROR,
|
| 83 |
'description' => $t('The Video Upload module has the required information, but was unable to authenticate to YouTube. There may be an error in one or more of the following: !list These settings can be reviewed <a href="!url">here</a>.', array('!list' => theme('item_list', array('username', 'password', 'developer key')), '!url' => url('admin/settings/video-upload'))),
|
| 84 |
);
|
| 85 |
}
|
| 86 |
|
| 87 |
if (empty($requirements) && empty($gdata_requirements)) {
|
| 88 |
$requirements['video_upload'] = array(
|
| 89 |
'title' => $t('Video Upload'),
|
| 90 |
'value' => $t('Properly configured'),
|
| 91 |
'severity' => REQUIREMENT_OK,
|
| 92 |
);
|
| 93 |
}
|
| 94 |
}
|
| 95 |
|
| 96 |
return array_merge($requirements, $gdata_requirements);
|
| 97 |
}
|
| 98 |
|
| 99 |
/**
|
| 100 |
* Implement hook_update_N().
|
| 101 |
*
|
| 102 |
* - Prefix "video_" onto status, status_ts and id column names.
|
| 103 |
* - Updates constants to simple text values rather than ambigous integers.
|
| 104 |
*/
|
| 105 |
function video_upload_update_6001() {
|
| 106 |
module_load_include('inc', 'content', 'includes/content.crud');
|
| 107 |
|
| 108 |
$fields = content_fields();
|
| 109 |
foreach ($fields as $field) {
|
| 110 |
if ($field['type'] == 'video_upload') {
|
| 111 |
$db_info = content_database_info($field);
|
| 112 |
if (isset($db_info['columns']['fid'])) {
|
| 113 |
$table = $db_info['table'];
|
| 114 |
// We're interested in id, status and status_ts.
|
| 115 |
$id_column = $db_info['columns']['id']['column'];
|
| 116 |
$id_schema = $db_info['columns']['id'];
|
| 117 |
db_change_field($ret, $table, $id_column, preg_replace('/(_id)$/', '_video_id', $id_column), $id_schema);
|
| 118 |
|
| 119 |
$status_column = $db_info['columns']['status']['column'];
|
| 120 |
$status_schema = $db_info['columns']['status'];
|
| 121 |
// Change type to varchar(32).
|
| 122 |
$status_schema['type'] = 'varchar';
|
| 123 |
$status_schema['length'] = 32;
|
| 124 |
$status_schema['default'] = VIDEO_UPLOAD_STATUS_UPLOAD_PENDING;
|
| 125 |
$new_status_column = preg_replace('/(_status)$/', '_video_status', $status_column);
|
| 126 |
db_change_field($ret, $table, $status_column, $new_status_column, $status_schema);
|
| 127 |
|
| 128 |
$status_ts_column = $db_info['columns']['status_ts']['column'];
|
| 129 |
$status_ts_schema = $db_info['columns']['status_ts'];
|
| 130 |
db_change_field($ret, $table, $status_ts_column, preg_replace('/(_status_ts)$/', '_video_status_ts', $status_ts_column), $status_ts_schema);
|
| 131 |
|
| 132 |
// Update to new constants.
|
| 133 |
foreach (_video_upload_update_6001_map_old_constants() as $old_status => $new_status) {
|
| 134 |
$ret[] = update_sql("UPDATE {" . $table . "} SET " . $new_status_column . " = '" . $new_status . "' WHERE " . $new_status_column . " = " . $old_status);
|
| 135 |
}
|
| 136 |
|
| 137 |
// Update CCK field definition.
|
| 138 |
$new_columns = $field['columns'];
|
| 139 |
foreach (array('id', 'status', 'status_ts') as $column) {
|
| 140 |
$new_columns['video_' . $column] = $new_columns[$column];
|
| 141 |
unset($new_columns[$column]);
|
| 142 |
}
|
| 143 |
$new_columns['video_status'] = $status_schema;
|
| 144 |
// Update table directly since CCK doesn't yet know that the
|
| 145 |
// module is filefield instead of video upload.
|
| 146 |
$record = new stdClass;
|
| 147 |
$record->db_columns = $new_columns;
|
| 148 |
$record->field_name = $field['field_name'];
|
| 149 |
drupal_write_record(content_field_tablename(), $record, 'field_name');
|
| 150 |
}
|
| 151 |
}
|
| 152 |
}
|
| 153 |
|
| 154 |
// Force a rebuild of CCK's type cache.
|
| 155 |
content_clear_type_cache(TRUE);
|
| 156 |
|
| 157 |
return $ret;
|
| 158 |
}
|
| 159 |
|
| 160 |
/**
|
| 161 |
* Map old constants to more sensbile values.
|
| 162 |
*/
|
| 163 |
function _video_upload_update_6001_map_old_constants() {
|
| 164 |
return array(
|
| 165 |
-3 => VIDEO_UPLOAD_STATUS_ORPHANED,
|
| 166 |
-2 => VIDEO_UPLOAD_STATUS_DELETE,
|
| 167 |
-1 => VIDEO_UPLOAD_STATUS_BAD,
|
| 168 |
0 => VIDEO_UPLOAD_STATUS_UNKNOWN,
|
| 169 |
1 => VIDEO_UPLOAD_STATUS_OK,
|
| 170 |
2 => VIDEO_UPLOAD_STATUS_OK_SYNCED,
|
| 171 |
3 => VIDEO_UPLOAD_STATUS_UPLOAD_PENDING,
|
| 172 |
);
|
| 173 |
}
|