recruiter/recruiter.install
2023-12-14 11:37:49 -06:00

59 lines
1.7 KiB
Plaintext

<?php
use Symfony\Component\Yaml\Yaml;
/**
* Create the table recruiter_users and create the recruiter.mail.yml config
*/
function recruiter_update_8001(&$sandbox) {
$schema['recruiter_users'] = [
'description' => 'Keep track of the users invited using the Delegater module',
'fields' => [
'uid' => [
'description' => 'Primary key: {users}.uid for user.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
'invitation_date' => [
'description' => 'The identifier of the data.',
'type' => 'varchar_ascii',
'length' => 128,
'not null' => TRUE,
'default' => '',
],
],
'primary key' => ['uid'],
'foreign keys' => [
'uid' => ['users' => 'uid'],
],
];
\Drupal::database()->schema()->createTable('mytable2', $schema['recruiter_users']);
// Drupal 9
// $config_path = drupal_get_path('module', 'recruiter') . '/config/install/recruiter.mail.yml';
// Drupal 10
$extension_path_resolver = Drupal::service('extension.path.resolver');
$config_path = $extension_path_resolver->getPath('module', 'recruiter') . '/config/install/recruiter.mail.yml';
// end of changes
$data = Yaml::parse(file_get_contents($config_path));
\Drupal::configFactory()->getEditable('recruiter.mail')->setData($data)->save(TRUE);
}
/**
* Rename the mytable2 to the correct name.
*/
function recruiter_update_8002(&$sandbox) {
\Drupal::database()->schema()->renameTable('mytable2', 'recruiter_users');
}
/**
* Delete the recruiter_users table.
*/
function recruiter_update_8005(&$sandbox) {
if (\Drupal::database()->schema()->tableExists('recruiter_users')) {
\Drupal::database()->schema()->dropTable('recruiter_users');
}
}