foldershare-8.x-1.2/foldershare.update.inc
foldershare.update.inc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | <?php /** * @file * Implements hooks to update the module. * * Note that comments on update functions are parsed and shown to the * site admin to describe an update before it is applied. */ use Drupal\Core\Database\Database; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\user\Entity\Role; use Drupal\foldershare\Constants; use Drupal\foldershare\Settings; use Drupal\foldershare\Utilities\ConfigurationUtilities; use Drupal\foldershare\Entity\FolderShare; use Drupal\foldershare\ManageUsageStatistics; use Drupal\foldershare\ManageSearch; /*---------------------------------------------------------------------- * * 0.5.0 to 0.5.1 * *----------------------------------------------------------------------*/ /** * Update the configurations for views, search, and entity views. * * These mandatory updates support a substantial overhaul of the user * interface that revises the module's views, entity view page, and search * indexing. Upon completion, the search index will be cleared and all site * caches flushed. */ function foldershare_update_8001(& $sandbox ) { // Restore the search configuration and clear the index. if (\Drupal::service( 'module_handler' )->moduleExists( 'search' ) === TRUE) { ConfigurationUtilities::revertConfiguration( 'core' , 'search.page.foldershare_search' ); search_index_clear(Constants::SEARCH_INDEX); } // Restore the view configuration. ConfigurationUtilities::revertConfiguration( 'view' , Constants::VIEW_LISTS); // Restore the entity display configuration. ConfigurationUtilities::revertConfiguration( 'core' , 'entity_view_display.foldershare.foldershare.default' ); } /*---------------------------------------------------------------------- * * 0.5.4 to 0.6.0 * *----------------------------------------------------------------------*/ /** * Update entity structure, entity view, and views tables. * * This mandatory update removes obsolete internal entity fields, adds new * internal entity fields, removes a text field formatter, adds new internal * field formatters, adds new menu commands, and adds a share-with-public * permission. * * Note that the entity view page and views tables are necessarily reset. * Any site customizations will be lost. */ function foldershare_update_8002() { $updateManager = \Drupal::entityDefinitionUpdateManager(); $connection = Database::getConnection(); $schema = $connection ->schema(); $baseTable = FolderShare::BASE_TABLE; $usageTable = ManageUsageStatistics::USAGE_TABLE; // // Update all entities with 'rootfolder' to use 'folder' instead. // -------------------------------------------------------------- // For all entities that use the old value, update to the new value. $connection ->update( $baseTable ) ->condition( 'kind' , 'rootfolder' , '=' ) ->fields([ 'kind' => FolderShare::FOLDER_KIND]) ->execute(); // // Remove 'nRootFolders' column from usage table. // ---------------------------------------------- // Remove the column. if ( $schema ->fieldExists( $usageTable , 'nRootFolders' ) === TRUE) { $schema ->dropField( $usageTable , 'nRootFolders' ); } // // Add 'systemhidden' and 'systemdisabled' fields. // ----------------------------------------------- // Update the base field definition. These definitions are copied from // the entity's base field definition for new installs. if ( $schema ->fieldExists( $baseTable , 'systemhidden' ) === FALSE) { // System hidden field flag. // - Boolean. // - Default is FALSE. // - 'view' unsupported. // - 'form' unsupported. // // Field editing blocked by FolderShareAccessControlHandler for all users. $definition = BaseFieldDefinition::create( 'boolean' ) ->setLabel(t( 'System hidden' )) ->setDescription(t( 'A TRUE/FALSE value indicating if the entity has been hidden by the system during special operations.' )) ->setRequired(FALSE) ->setDefaultValue(FALSE) ->setDisplayConfigurable( 'form' , FALSE) ->setDisplayConfigurable( 'view' , FALSE); // Add the field. $updateManager ->installFieldStorageDefinition( 'systemhidden' , FolderShare::ENTITY_TYPE_ID, FolderShare::ENTITY_TYPE_ID, $definition ); } if ( $schema ->fieldExists( $baseTable , 'systemdisabled' ) === FALSE) { // System disabled field flag. // - Boolean. // - Default is FALSE. // - 'view' unsupported. // - 'form' unsupported. // // Field editing blocked by FolderShareAccessControlHandler for all users. $definition = BaseFieldDefinition::create( 'boolean' ) ->setLabel(t( 'System disabled' )) ->setDescription(t( 'A TRUE/FALSE value indicating if the entity has been disabled by the system during special operations.' )) ->setRequired(FALSE) ->setDefaultValue(FALSE) ->setDisplayConfigurable( 'form' , FALSE) ->setDisplayConfigurable( 'view' , FALSE); // Add the field. $updateManager ->installFieldStorageDefinition( 'systemdisabled' , FolderShare::ENTITY_TYPE_ID, FolderShare::ENTITY_TYPE_ID, $definition ); } // // Update all entities to default 'systemhidden' and 'systemdisabled' values. // -------------------------------------------------------------------------- // Default to FALSE. $connection ->update(FolderShare::BASE_TABLE) ->fields([ 'systemhidden' => (int) 0, 'systemdisabled' => (int) 0, ]) ->execute(); // // Remove 'grantdisableduids' field. // --------------------------------- // Update the base field definition. $definition = $updateManager ->getFieldStorageDefinition( 'grantdisableduids' , FolderShare::ENTITY_TYPE_ID); if ( $definition !== NULL) { $updateManager ->uninstallFieldStorageDefinition( $definition ); // Uninstallling a field marks the field as deleted data. Future // runs of CRON will delete the field data in batches until all // entities have been updated, and then the multi-value table // will be automatically dropped. } // // Flush all caches. // ----------------- // Render and views now use 'systemhidden' and 'systemdisabled', so their // caches need to be flushed. The breadcrumb builder's interface has changed, // and the field formatter plugins have been updated. There are also new // menu commands and a new permission. // // The cache must be flushed now before we install configurations that use // the new field formatters, use the new menu commands, or use the new // permission. drupal_flush_all_caches(); // // Reset views. // ------------ // The new views use new field formatters, check the 'systemhidden' flag, // and support lists in dialogs. ConfigurationUtilities::revertConfiguration( 'view' , Constants::VIEW_LISTS); // // Reset entity view. // ------------------ // The previous release included a text display field formatter that has // been removed. ConfigurationUtilities::revertConfiguration( 'core' , 'entity_view_display.foldershare.foldershare.default' ); // // Enable new menu commands. // ------------------------- // Insure the new menu commands are enabled by default. $currentCommands = Settings::getCommandMenuAllowed(); if (in_array( 'foldersharecommand_delete_as_admin' , $currentCommands ) === FALSE) { $currentCommands [] = 'foldersharecommand_delete_as_admin' ; } if (in_array( 'foldersharecommand_delete_on_rootlist' , $currentCommands ) === FALSE) { $currentCommands [] = 'foldersharecommand_delete_on_rootlist' ; } if (in_array( 'foldersharecommand_release_share' , $currentCommands ) === FALSE) { $currentCommands [] = 'foldersharecommand_release_share' ; } Settings::setCommandMenuAllowed( $currentCommands ); // // Enable the share-with-public permission for roles with share permission. // ------------------------------------------------------------------------ // The old "share" permission shared with others or public. The new one only // shares with others, and a new "share with public" permission shares with // the public. If user roles had the old "share" permission, give them both // share permissions now. foreach (\Drupal::entityQuery( 'user_role' )->execute() as $roleId ) { $role = Role::load( $roleId ); if ( $role !== NULL) { if ( $role ->hasPermission(Constants::SHARE_PERMISSION) === TRUE) { $role ->grantPermission(Constants::SHARE_PUBLIC_PERMISSION); $role ->save(); } } } return t( 'Update complete. Note that the entity view page and view lists configurations have been necessarily reset to defaults.' ); } /*---------------------------------------------------------------------- * * 0.6.0 to 0.6.1 * *----------------------------------------------------------------------*/ /** * Update default enabled commands. * * This mandatory update adds new menu commands. */ function foldershare_update_8003() { // // Enable new menu commands. // ------------------------- // Insure the new menu commands are enabled by default. $currentCommands = Settings::getCommandMenuAllowed(); if (in_array( 'foldersharecommand_move_as_admin' , $currentCommands ) === FALSE) { $currentCommands [] = 'foldersharecommand_move_as_admin' ; } if (in_array( 'foldersharecommand_move_on_rootlist' , $currentCommands ) === FALSE) { $currentCommands [] = 'foldersharecommand_move_on_rootlist' ; } Settings::setCommandMenuAllowed( $currentCommands ); } /** * Flush all caches. */ function foldershare_update_8004() { // This update is intentionally empty. Its effect is to cause all // caches to be flushed. return t( 'Update complete.' ); } /*---------------------------------------------------------------------- * * 0.6.1 to 0.6.2 * *----------------------------------------------------------------------*/ /** * Update views and add an internal entity type for scheduled tasks. * * This mandatory update fixes a problem with views that allowed some * displays to show hidden items. It also installs a new internal entity type * that manages scheduled background tasks. * * Note that the views lists must be reset. Any site customizations will * be lost. */ function foldershare_update_8005() { // // Install FolderShareScheduledTask. // --------------------------------- // Get the definition for the new FolderShareScheduledTask entity // and install it. $updateManager = \Drupal::entityDefinitionUpdateManager(); if ( $updateManager ->getEntityType( 'foldershare_scheduledtask' ) === NULL) { $typeManager = \Drupal::entityTypeManager(); $definition = $typeManager ->getDefinition( 'foldershare_scheduledtask' , FALSE); if ( $definition !== NULL) { $updateManager ->installEntityType( $definition ); } } // // Reset views. // ------------ // All views now check the 'systemhidden' flag. ConfigurationUtilities::revertConfiguration( 'view' , Constants::VIEW_LISTS); return t( 'Update complete. Note that the view lists configurations have been necessarily reset to defaults.' ); } /*---------------------------------------------------------------------- * * 0.6.2 to 0.6.3 * *----------------------------------------------------------------------*/ /** * Update entity definition for internal scheduled tasks. * * This mandatory update reduces the visibility of the internal scheduled * task entity. This makes its fields unavailable on pages, through entity * references, or within views. */ function foldershare_update_8006() { // This update is intentionally empty. Its effect is to cause all // caches to be flushed, which will pick up changes to the entity type. return t( 'Update complete.' ); } /*---------------------------------------------------------------------- * * 0.6.3 to 0.6.4 * *----------------------------------------------------------------------*/ /** * Update entity definition for FolderShare entities. * * This mandatory update disables the static and render cache for * FolderShare entities. */ function foldershare_update_8007() { // This update is intentionally empty. Its effect is to cause all // caches to be flushed, which will pick up changes to the entity type. return t( 'Update complete.' ); } /*---------------------------------------------------------------------- * * 0.6.4 to 0.6.5 * *----------------------------------------------------------------------*/ /** * Update enabled menu commands. * * This mandatory update disables the compress and uncompress commands, * which are in development and not yet ready for production sites. */ function foldershare_update_8008() { // To disable the compress and uncompress commands, we need to force // an enable of command menu restrictions, and then intentionally not // list these commands in the list of allowed commands. Settings::setCommandMenuRestrict(TRUE); $allowedCommands = Settings::getCommandMenuAllowed(); $keepCommands = []; foreach ( $allowedCommands as $command ) { switch ( $command ) { case 'foldersharecommand_archive' : case 'foldersharecommand_unarchive' : break ; default : $keepCommands [] = $command ; break ; } } Settings::setCommandMenuAllowed( $keepCommands ); return t( 'Update complete.' ); } /*---------------------------------------------------------------------- * * 0.6.8 to 1.2.0 * *----------------------------------------------------------------------*/ /** * Updates to forms, settings, and routes. * * This mandatory update modifies search indexing, forms, usage reporting, * logging, hooks, and background task scheduling. Some routes and services * have changed. REST web services have been removed from this module and * are now available via the separate FolderShare REST module. */ function foldershare_update_8009() { // Search indexing has changed slightly. Mark everything as in need of // reindexing. ManageSearch::markForReindex(); // Delete the old REST configuration now that REST has been moved to // a separate module. $configStorage = \Drupal::service( 'config.storage' ); $configStorage -> delete ( 'rest.resource.entity.foldershare' ); // The update will trigger a full cache flush will pick up the route // and services chasnges. return t( 'Update complete.' ); } |