Changeset 9539 for extensions/community/maintain.inc.php
- Timestamp:
- Mar 4, 2011, 11:39:51 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/community/maintain.inc.php
r9500 r9539 103 103 pwg_query($query); 104 104 } 105 106 function plugin_activate() 107 { 108 community_get_data_from_core21(); 109 community_get_data_from_community21(); 110 } 111 112 function community_get_data_from_core21() 113 { 114 global $conf, $prefixeTable; 115 116 $from_piwigo21_file = $conf['local_data_dir'].'/plugins/core_user_upload_to_community.php'; 117 if (is_file($from_piwigo21_file)) 118 { 119 include($from_piwigo21_file); 120 $user_upload_conf = unserialize($user_upload_conf); 121 122 include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); 123 prepare_upload_configuration(); 124 125 $user_upload_conf['upload_user_access'] = 1; 126 127 if (isset($user_upload_conf['uploadable_categories']) and is_array($user_upload_conf['uploadable_categories'])) 128 { 129 $type = 'any_registered_user'; 130 if (isset($user_upload_conf['upload_user_access']) and 1 == $user_upload_conf['upload_user_access']) 131 { 132 $type = 'any_visitor'; 133 } 134 135 $inserts = array(); 136 137 foreach ($user_upload_conf['uploadable_categories'] as $category_id) 138 { 139 array_push( 140 $inserts, 141 array( 142 'type' => $type, 143 'category_id' => $category_id, 144 'recursive' => 'false', 145 'create_subcategories' => 'false', 146 'moderated' => 'true', 147 ) 148 ); 149 } 150 151 if (count($inserts) > 0) 152 { 153 mass_inserts( 154 $prefixeTable.'community_permissions', 155 array_keys($inserts[0]), 156 $inserts 157 ); 158 } 159 } 160 161 if (isset($user_upload_conf['waiting_rows']) and is_array($user_upload_conf['waiting_rows'])) 162 { 163 $id_of_user = array(); 164 165 $query = ' 166 SELECT 167 '.$conf['user_fields']['id'].' AS id, 168 '.$conf['user_fields']['username'].' AS username 169 FROM '.USERS_TABLE.' 170 ;'; 171 $result = pwg_query($query); 172 while ($row = pwg_db_fetch_assoc($result)) 173 { 174 $id_of_user[ $row['username'] ] = $row['id']; 175 } 176 177 $inserts = array(); 178 179 foreach ($user_upload_conf['waiting_rows'] as $pending) 180 { 181 $source_path = get_complete_dir($pending['storage_category_id']).$pending['file']; 182 183 if (is_file($source_path)) 184 { 185 $image_id = add_uploaded_file($source_path, $pending['file'], array($pending['storage_category_id']), 16); 186 187 array_push( 188 $inserts, 189 array( 190 'image_id' => $image_id, 191 'added_on' => date ('Y-m-d H:i:s', $pending['date']), 192 'state' => 'moderation_pending', 193 ) 194 ); 195 196 $data = array(); 197 198 if (isset($pending['username']) and isset($id_of_user[ $pending['username'] ])) 199 { 200 $data['added_by'] = $id_of_user[ $pending['username'] ]; 201 } 202 203 foreach (array('date_creation', 'author', 'name', 'comment') as $field) 204 { 205 $value = getAttribute($pending['infos'], $field); 206 if (!empty($value)) 207 { 208 $data[$field] = pwg_db_real_escape_string($value); 209 } 210 } 211 212 if (count($data) > 0) 213 { 214 $data['id'] = $image_id; 215 216 mass_updates( 217 IMAGES_TABLE, 218 array( 219 'primary' => array('id'), 220 'update' => array_keys($data) 221 ), 222 array($data) 223 ); 224 } 225 226 // deletion 227 unlink($source_path); 228 if (!isset($pending['tn_ext'])) 229 { 230 $pending['tn_ext'] = 'jpg'; 231 } 232 @unlink(get_thumbnail_path(array('path'=>$source_path, 'tn_ext'=>$pending['tn_ext']))); 233 } 234 } 235 236 if (count($inserts) > 0) 237 { 238 mass_inserts( 239 $prefixeTable.'community_pendings', 240 array_keys($inserts[0]), 241 $inserts 242 ); 243 } 244 } 245 unlink($from_piwigo21_file); 246 } 247 } 248 249 function community_get_data_from_community21() 250 { 251 global $prefixeTable; 252 253 $old_community_table = $prefixeTable.'community'; 254 $query = 'SHOW TABLES;'; 255 $result = pwg_query($query); 256 while ($row = pwg_db_fetch_row($result)) 257 { 258 if ($old_community_table == $row[0]) 259 { 260 $inserts = array(); 261 262 $query = ' 263 SELECT 264 * 265 FROM '.$old_community_table.' 266 ;'; 267 $result = pwg_query($query); 268 while ($row = pwg_db_fetch_assoc($result)) 269 { 270 array_push( 271 $inserts, 272 array( 273 'type' => 'user', 274 'user_id' => $row['user_id'], 275 'category_id' => null, 276 'recursive' => 'true', 277 'create_subcategories' => $row['permission_level'] == 2 ? 'true' : 'false', 278 'moderated' => 'false', 279 ) 280 ); 281 } 282 283 if (count($inserts) > 0) 284 { 285 mass_inserts( 286 $prefixeTable.'community_permissions', 287 array_keys($inserts[0]), 288 $inserts 289 ); 290 } 291 292 $query = 'DROP TABLE '.$old_community_table.';'; 293 pwg_query($query); 294 295 break; 296 } 297 } 298 } 105 299 ?>
Note: See TracChangeset
for help on using the changeset viewer.