Issue #2784921 by amateescu, timmillwood, pk188, plach, catch, Fabianx, dixon_, dawehner, borisson_, Sam152, yoroy, webchick, phenaproxima, larowlan: Add Workspaces experimental module
2018-05-04 12:13:32 +00:00
< ? php
/**
* @ file
2018-07-24 11:36:16 +00:00
* Contains install , update and uninstall functions for the Workspaces module .
Issue #2784921 by amateescu, timmillwood, pk188, plach, catch, Fabianx, dixon_, dawehner, borisson_, Sam152, yoroy, webchick, phenaproxima, larowlan: Add Workspaces experimental module
2018-05-04 12:13:32 +00:00
*/
Issue #3087644 by jibran, Berdir, alexpott, longwave, Wim Leers, amateescu, catch, xjm, larowlan, dpi, quietone: Remove Drupal 8 updates up to and including 88**
2020-01-24 23:52:03 +00:00
use Drupal\Core\Entity\EntityTypeInterface ;
2018-07-24 11:36:16 +00:00
use Drupal\workspaces\Entity\Workspace ;
Issue #2784921 by amateescu, timmillwood, pk188, plach, catch, Fabianx, dixon_, dawehner, borisson_, Sam152, yoroy, webchick, phenaproxima, larowlan: Add Workspaces experimental module
2018-05-04 12:13:32 +00:00
2018-07-06 16:27:53 +00:00
/**
* Implements hook_requirements () .
*/
2018-07-24 11:36:16 +00:00
function workspaces_requirements ( $phase ) {
2018-07-06 16:27:53 +00:00
$requirements = [];
2018-07-24 11:36:16 +00:00
if ( $phase === 'install' ) {
if ( \Drupal :: moduleHandler () -> moduleExists ( 'workspace' )) {
$requirements [ 'workspace_incompatibility' ] = [
'severity' => REQUIREMENT_ERROR ,
'description' => t ( 'Workspaces can not be installed when the contributed Workspace module is also installed. See the <a href=":link">upgrade path</a> page for more information on how to upgrade.' , [
':link' => 'https://www.drupal.org/node/2987783' ,
]),
];
}
2018-07-06 16:27:53 +00:00
}
return $requirements ;
}
2019-09-20 10:17:19 +00:00
/**
* Implements hook_module_preinstall () .
*/
function workspaces_module_preinstall ( $module ) {
if ( $module !== 'workspaces' ) {
return ;
}
/** @var \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager */
$workspace_manager = \Drupal :: service ( 'workspaces.manager' );
$entity_definition_update_manager = \Drupal :: entityDefinitionUpdateManager ();
foreach ( $entity_definition_update_manager -> getEntityTypes () as $entity_type ) {
if ( $workspace_manager -> isEntityTypeSupported ( $entity_type )) {
2020-02-24 13:25:58 +00:00
$entity_type -> setRevisionMetadataKey ( 'workspace' , 'workspace' );
2019-09-20 10:17:19 +00:00
$entity_definition_update_manager -> updateEntityType ( $entity_type );
}
}
}
Issue #2784921 by amateescu, timmillwood, pk188, plach, catch, Fabianx, dixon_, dawehner, borisson_, Sam152, yoroy, webchick, phenaproxima, larowlan: Add Workspaces experimental module
2018-05-04 12:13:32 +00:00
/**
* Implements hook_install () .
*/
2018-07-24 11:36:16 +00:00
function workspaces_install () {
2022-01-01 16:19:49 +00:00
// Set the owner of these default workspaces to be first user which has the
// 'administrator' role. This way we avoid hard coding user ID 1 for sites
Issue #2784921 by amateescu, timmillwood, pk188, plach, catch, Fabianx, dixon_, dawehner, borisson_, Sam152, yoroy, webchick, phenaproxima, larowlan: Add Workspaces experimental module
2018-05-04 12:13:32 +00:00
// that prefer to not give it any special meaning.
$admin_roles = \Drupal :: entityTypeManager () -> getStorage ( 'user_role' ) -> getQuery ()
-> condition ( 'is_admin' , TRUE )
-> execute ();
if ( ! empty ( $admin_roles )) {
$query = \Drupal :: entityTypeManager () -> getStorage ( 'user' ) -> getQuery ()
2021-04-12 09:40:17 +00:00
-> accessCheck ( FALSE )
Issue #2784921 by amateescu, timmillwood, pk188, plach, catch, Fabianx, dixon_, dawehner, borisson_, Sam152, yoroy, webchick, phenaproxima, larowlan: Add Workspaces experimental module
2018-05-04 12:13:32 +00:00
-> condition ( 'roles' , $admin_roles , 'IN' )
-> condition ( 'status' , 1 )
-> sort ( 'uid' , 'ASC' )
-> range ( 0 , 1 );
$result = $query -> execute ();
}
// Default to user ID 1 if we could not find any other administrator users.
$owner_id = ! empty ( $result ) ? reset ( $result ) : 1 ;
2019-08-30 11:59:59 +00:00
// Create a 'stage' workspace by default.
Issue #2784921 by amateescu, timmillwood, pk188, plach, catch, Fabianx, dixon_, dawehner, borisson_, Sam152, yoroy, webchick, phenaproxima, larowlan: Add Workspaces experimental module
2018-05-04 12:13:32 +00:00
Workspace :: create ([
'id' => 'stage' ,
'label' => 'Stage' ,
'uid' => $owner_id ,
]) -> save ();
}
2019-09-20 10:17:19 +00:00
/**
* Implements hook_schema () .
*/
function workspaces_schema () {
$schema [ 'workspace_association' ] = [
'description' => 'Stores the association between entity revisions and their workspace.' ,
'fields' => [
'workspace' => [
'type' => 'varchar_ascii' ,
'length' => 128 ,
'not null' => TRUE ,
'default' => '' ,
'description' => 'The workspace ID.' ,
],
'target_entity_type_id' => [
'type' => 'varchar_ascii' ,
'length' => EntityTypeInterface :: ID_MAX_LENGTH ,
'not null' => TRUE ,
'default' => '' ,
'description' => 'The ID of the associated entity type.' ,
],
'target_entity_id' => [
'type' => 'int' ,
'unsigned' => TRUE ,
'not null' => TRUE ,
'description' => 'The ID of the associated entity.' ,
],
'target_entity_revision_id' => [
'type' => 'int' ,
'unsigned' => TRUE ,
'not null' => TRUE ,
'description' => 'The revision ID of the associated entity.' ,
],
],
'indexes' => [
'target_entity_revision_id' => [ 'target_entity_revision_id' ],
],
'primary key' => [ 'workspace' , 'target_entity_type_id' , 'target_entity_id' ],
];
return $schema ;
}
/**
Issue #3087644 by jibran, Berdir, alexpott, longwave, Wim Leers, amateescu, catch, xjm, larowlan, dpi, quietone: Remove Drupal 8 updates up to and including 88**
2020-01-24 23:52:03 +00:00
* Implements hook_update_last_removed () .
2020-01-22 00:30:15 +00:00
*/
Issue #3087644 by jibran, Berdir, alexpott, longwave, Wim Leers, amateescu, catch, xjm, larowlan, dpi, quietone: Remove Drupal 8 updates up to and including 88**
2020-01-24 23:52:03 +00:00
function workspaces_update_last_removed () {
2020-03-05 08:58:41 +00:00
return 8803 ;
2019-12-17 09:44:10 +00:00
}