-
Notifications
You must be signed in to change notification settings - Fork 6
/
tmgmt.install
877 lines (841 loc) · 25.6 KB
/
tmgmt.install
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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
<?php
/**
* @file
* Installation hooks for the Translation Management module.
*/
/**
* Implements hook_uninstall().
*/
function tmgmt_uninstall() {
// Remove all variables that we added.
variable_del('tmgmt_quick_checkout');
variable_del('tmgmt_purge_finished');
}
/**
* Implements hook_schema().
*/
function tmgmt_schema() {
$schema['tmgmt_job'] = array(
'description' => 'A translation job represents a translation order that can be assigned to a translator.',
'fields' => array(
'tjid' => array(
'description' => 'The identifier of the translation job.',
'type' => 'serial',
'not null' => TRUE,
),
'source_language' => array(
'description' => 'The source language of the data.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
),
'target_language' => array(
'description' => 'The language the data should be translated to.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
),
'state' => array(
'description' => 'The state of the translation job.',
'type' => 'int',
'not null' => TRUE,
),
'created' => array(
'description' => 'Created timestamp.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'changed' => array(
'description' => 'Changed timestamp.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'translator' => array(
'description' => 'Machine name of the translator.',
'type' => 'varchar',
'length' => 128,
),
'settings' => array(
'description' => 'Translator specific configuration and context for this job.',
'type' => 'text',
'size' => 'big',
'serialize' => TRUE,
),
'reference' => array(
'description' => 'Remote identifier of this translation job.',
'type' => 'varchar',
'length' => 255,
),
'uid' => array(
'description' => 'uid of the job creator',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'label' => array(
'description' => 'Optional user provided label of the job.',
'type' => 'varchar',
'length' => 255,
),
),
'primary key' => array('tjid'),
'indexes' => array(
'state' => array('state'),
'reference' => array('reference'),
),
);
$schema['tmgmt_remote'] = array(
'description' => 'TMGMT job remote mapping.',
'fields' => array(
'trid' => array(
'description' => 'The primary key.',
'type' => 'serial',
'not null' => TRUE,
),
'tjid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => '{tmgmt_job}.tjid foreign key',
),
'tjiid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => '{tmgmt_job_item}.tjjid foreign key',
),
'data_item_key' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Translation job data item key.',
),
'remote_identifier_1' => array(
'type' => 'varchar',
'length' => 127,
'not null' => TRUE,
'default' => '',
'description' => 'Custom remote identifier data.',
),
'remote_identifier_2' => array(
'type' => 'varchar',
'length' => 127,
'not null' => TRUE,
'default' => '',
'description' => 'Custom remote identifier data.',
),
'remote_identifier_3' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Custom remote identifier data.',
),
'remote_url' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Remote job url.',
),
'word_count' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Word count info provided by the remote service.',
),
'amount' => array(
'type' => 'int',
'size' => 'big',
'not null' => TRUE,
'default' => 0,
'description' => 'Amount charged for the remote translation job.',
),
'currency' => array(
'type' => 'char',
'length' => 3,
'not null' => TRUE,
'default' => '',
'description' => 'Amount charged currency.',
),
'remote_data' => array(
'description' => 'Custom remote data.',
'type' => 'text',
'size' => 'big',
'serialize' => TRUE,
),
),
'primary key' => array('trid'),
'indexes' => array(
'tjid' => array('tjid'),
'tjiid' => array('tjiid'),
'remote_identifiers' => array('remote_identifier_1', 'remote_identifier_2'),
),
);
$schema['tmgmt_job_item'] = array(
'description' => 'A job item connects a source to a translation job.',
'fields' => array(
'tjiid' => array(
'description' => 'The identifier of the translation job item.',
'type' => 'serial',
'not null' => TRUE,
),
'tjid' => array(
'description' => 'The identifier of the translation job.',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
),
'plugin' => array(
'description' => 'Indicates the plugin which provides this item.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
'item_type' => array(
'description' => 'The type of the item, e.g. the entity type.',
'type' => 'varchar',
'length' => 128,
),
'item_id' => array(
'description' => 'The unique id (within the given item type) of the item.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
'state' => array(
'description' => 'The state of the translation job item.',
'type' => 'int',
'not null' => TRUE,
),
'data' => array(
'description' => 'Can be used by the source plugin to store the data if it can not be retrieved anymore later on.',
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
'serialize' => TRUE,
),
'changed' => array(
'description' => 'Changed timestamp.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'count_pending' => array(
'description' => 'Counter for all pending data items.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'count_translated' => array(
'description' => 'Counter for all translated data items.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'count_accepted' => array(
'description' => 'Counter for all accepted data items.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'count_reviewed' => array(
'description' => 'Counter for all reviewed data items.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'word_count' => array(
'description' => 'Word count of all texts contained in this job item.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('tjiid'),
'indexes' => array(
'job_id' => array('tjid'),
),
'foreign keys' => array(
'job' => array(
'table' => 'tmgmt_job',
'columns' => array('tjid'),
),
),
);
$schema['tmgmt_translator'] = array(
'description' => 'A translator is a combination of a translator type and type specific configuration.',
'fields' => array(
'tid' => array(
'description' => 'The identifier of the translator.',
'type' => 'serial',
'not null' => TRUE,
),
'name' => array(
'description' => 'Machine name identifier of the translator.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
'label' => array(
'description' => 'Label of the translator.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'description' => array(
'description' => 'Description of the translator.',
'type' => 'text',
'size' => 'medium',
),
'plugin' => array(
'description' => 'Name of the translator service plugin.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
'settings' => array(
'description' => 'Translator specific settings.',
'type' => 'text',
'size' => 'big',
'serialize' => TRUE,
),
'weight' => array(
'description' => 'The weight of the translator.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'status' => array(
'description' => 'The exportable status of the entity.',
'type' => 'int',
'not null' => TRUE,
// Set the default to ENTITY_CUSTOM without using the constant as it is
// not safe to use it at this point.
'default' => 0x01,
'size' => 'tiny',
),
'module' => array(
'description' => 'The name of the providing module if the entity has been defined in code.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
'primary key' => array('tid'),
'unique keys' => array(
'name' => array('name'),
),
);
$schema['tmgmt_message'] = array(
'description' => 'A log message can be used to store events that affect a job.',
'fields' => array(
'mid' => array(
'description' => 'The identifier of the message.',
'type' => 'serial',
'not null' => TRUE,
),
'tjid' => array(
'description' => 'The identifier of the translation job that the message belongs to.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'tjiid' => array(
'description' => 'The identifier of the translation job item that the message belongs to.',
'type' => 'int',
'unsigned' => TRUE,
),
'uid' => array(
'description' => 'The identifier of the user who performed the action.',
'type' => 'int',
'unsigned' => TRUE,
'default' => 0,
),
'message' => array(
'description' => 'The language into the data should be translated.',
'type' => 'text',
'size' => 'big',
),
'variables' => array(
'description' => 'The variables of the message as expected by t().',
'type' => 'text',
'size' => 'big',
'serialize' => TRUE,
),
'created' => array(
'description' => 'Created timestamp.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type' => array(
'description' => 'Type of the message (debug, notice, warning or error)',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
),
'primary key' => array('mid'),
'indexes' => array(
'tjid' => array('tjid'),
'tjiid' => array('tjiid'),
),
);
// Clone the schema for our cache table from Drupal core.
$schema['cache_tmgmt'] = drupal_get_schema_unprocessed('system', 'cache');
// Clone the schema for the entity cache module if it is enabled.
if (module_exists('entitycache')) {
$schema['cache_entity_tmgmt_translator'] = drupal_get_schema_unprocessed('system', 'cache');
}
return $schema;
}
/**
* Merge the content of the 'translation' field into the 'data' field.
*/
function tmgmt_update_7000(&$sandbox) {
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['max'] = db_query('SELECT COUNT(*) FROM {tmgmt_job_item}')->fetchField();
}
$results = db_select('tmgmt_job_item', 'tji')
->fields('tji', array('tjiid', 'data', 'translation'))
->range($sandbox['progress'], 50)
->orderBy('tjiid', 'ASC')
->execute();
foreach ($results as $item) {
$data = unserialize($item->data);
if (!empty($item->translation)) {
foreach (tmgmt_flatten_data(unserialize($item->translation)) as $key => $translation) {
if (!empty($item->data)) {
$key = explode('][', $key);
drupal_array_set_nested_value($data, array_merge($key, array('#translation')), $translation);
}
}
db_update('tmgmt_job_item')
->condition('tjiid', $item->tjiid)
->fields(array('data' => serialize($data)))
->execute();
}
$sandbox['progress']++;
}
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
}
/**
* Remove the 'translation' field from the job item entity.
*/
function tmgmt_update_7001() {
db_drop_field('tmgmt_job_item', 'translation');
}
/**
* Add counter columns to {tmgmt_job_item}.
*/
function tmgmt_update_7002() {
// Defining schema of additional fields.
$schema = array(
'count_pending' => array(
'description' => 'Counter for all pending data items.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'count_translated' => array(
'description' => 'Counter for all translated data items.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'count_approved' => array(
'description' => 'Counter for all approved data items.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
);
// Add aditional fields to db.
foreach ($schema as $field => $spec) {
db_add_field('tmgmt_job_item', $field, $spec);
}
}
/**
* Data parsing helper function for tmgmt_update_7003().
*
* Copied from TMGMTJobItemController::count().
*
* @param $item
* The current data item.
* @param $entity
* The job item the count should be calculated.
*/
function _tmgmt_data_count_7003(&$item, $entity) {
if (!empty($item['#text'])) {
if (_tmgmt_filter_data($item)) {
// Set default states if no state is set.
if (!isset($item['#status'])) {
// Translation is present.
if (!empty($item['#translation'])) {
$item['#status'] = TMGMT_DATA_ITEM_STATE_TRANSLATED;
}
// No translation present.
else {
$item['#status'] = TMGMT_DATA_ITEM_STATE_PENDING;
}
}
switch ($item['#status']) {
case 1:
$entity->count_approved++;
break;
case 2:
$entity->count_translated++;
break;
default:
$entity->count_pending++;
break;
}
}
}
else {
foreach (element_children($item) as $key) {
_tmgmt_data_count_7003($item[$key], $entity);
}
}
}
/**
* Set counters for existing job items.
*/
function tmgmt_update_7003(&$sandbox) {
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['last_tjiid'] = 0;
$sandbox['max'] = db_query('SELECT COUNT(tjiid) FROM {tmgmt_job_item}')->fetchField();
}
$result = db_query('SELECT tjiid, data FROM {tmgmt_job_item} WHERE tjiid > :last_tjiid ORDER BY tjiid LIMIT 10', array( ':last_tjiid' => $sandbox['last_tjiid']));
foreach ($result as $row) {
// Unseralize data, count it and then save the counters.
if (!empty($row->data)) {
$fake_job_item = (object)array(
'count_approved' => 0,
'count_translated' => 0,
'count_pending' => 0,
);
$data = unserialize($row->data);
_tmgmt_data_count_7003($data, $fake_job_item);
$fields = (array)$fake_job_item + array(
'data' => serialize($data),
);
db_update('tmgmt_job_item')
->condition('tjiid', $row->tjiid)
->fields($fields)
->execute();
}
$sandbox['progress']++;
}
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
if ($row) {
$sandbox['last_tjiid'] = $row->tjiid;
}
}
/**
* Replace the [#translation][#finished] attribute with [#status].
*/
function tmgmt_update_7004(&$sandbox) {
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['last_tjiid'] = 0;
$sandbox['max'] = db_query('SELECT COUNT(tjiid) FROM {tmgmt_job_item}')->fetchField();
}
$result = db_query('SELECT tjiid, data FROM {tmgmt_job_item} WHERE tjiid > :last_tjiid ORDER BY tjiid LIMIT 10', array(':last_tjiid' => $sandbox['last_tjiid']));
foreach ($result as $row) {
if (!empty($row->data)) {
$data = unserialize($row->data);
$flattened_data = array_filter(tmgmt_flatten_data($data), '_tmgmt_filter_data');
// Loop over data, find finished translations, remove the flag and set
// the status instead.
foreach ($flattened_data as $key => $values) {
if (!empty($values['#translation']['#finished'])) {
$finished = $values['#translation']['#finished'];
unset($values['#translation']['#finished']);
drupal_array_set_nested_value($data, array_merge($key, array('#translation')), $values['#translation']);
if ($finished && (empty($values['#status']) || $values['#status'] == TMGMT_DATA_ITEM_STATE_PENDING)) {
drupal_array_set_nested_value($data, array_merge($key, array('#status')), TMGMT_DATA_ITEM_STATE_TRANSLATED);
}
// Save the updated data structure.
db_update('tmgmt_job_item')
->condition('tjiid', $row->tjiid)
->fields(array('data' => serialize($data)))
->execute();
}
}
}
$sandbox['progress']++;
}
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
if ($row) {
$sandbox['last_tjiid'] = $row->tjiid;
}
}
/**
* Add word count column to {tmgmt_job_item}.
*/
function tmgmt_update_7005() {
if (!db_field_exists('tmgmt_job_item', 'word_count')) {
$spec = array(
'description' => 'Word count of all texts contained in this job item.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
);
db_add_field('tmgmt_job_item', 'word_count', $spec);
}
}
/**
* Data parsing helper function for tmgmt_update_7006().
*
* Copied from TMGMTJobItemController::count().
*
* @param $item
* The current data item.
* @param $entity
* The job item the count should be calculated.
*/
function _tmgmt_data_count_7006($item, $entity) {
if (!empty($item['#text'])) {
if (_tmgmt_filter_data($item)) {
module_load_include('module', 'tmgmt');
// Count words of the data item.
$entity->word_count += tmgmt_word_count($item['#text']);
}
}
else {
foreach (element_children($item) as $key) {
_tmgmt_data_count_7006($item[$key], $entity);
}
}
}
/**
* Set word count for existing job items.
*/
function tmgmt_update_7006(&$sandbox) {
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['last_tjiid'] = 0;
$sandbox['max'] = db_query('SELECT COUNT(tjiid) FROM {tmgmt_job_item}')->fetchField();
}
$result = db_query('SELECT tjiid, data FROM {tmgmt_job_item} WHERE tjiid > :last_tjiid ORDER BY tjiid LIMIT 10', array(':last_tjiid' => $sandbox['last_tjiid']));
foreach ($result as $row) {
// Unseralize data, count it and then save the counters.
if (!empty($row->data)) {
$fake_job_item = (object)array(
'word_count' => 0,
);
_tmgmt_data_count_7006(unserialize($row->data), $fake_job_item);
db_update('tmgmt_job_item')
->condition('tjiid', $row->tjiid)
->fields((array)$fake_job_item)
->execute();
}
$sandbox['progress']++;
}
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
if ($row) {
$sandbox['last_tjiid'] = $row->tjiid;
}
}
/**
* Removing the tmgmt_auto_accept variable.
*/
function tmgmt_update_7007() {
variable_del('tmgmt_auto_accept');
}
/**
* Introduce the reviewed counter and rename approved.
*/
function tmgmt_update_7008() {
// Rename approved to reviewed to simplify the upgrade path.
db_change_field('tmgmt_job_item', 'count_approved', 'count_reviewed', array(
'description' => 'Counter for all reviewed data items.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
));
// Add the accepted counter.
db_add_field('tmgmt_job_item', 'count_accepted', array(
'description' => 'Counter for all accepted data items.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
));
}
/**
* Update data item status of accepted job items to accepted.
*/
function tmgmt_update_7009() {
// First set count_accepted to the value of count_reviewed.
db_update('tmgmt_job_item')
->expression('count_accepted', 'count_reviewed + count_pending + count_translated')
->condition('state', TMGMT_JOB_ITEM_STATE_ACCEPTED)
->execute();
// Then set count_reviewed to 0.
db_update('tmgmt_job_item')
->fields(array(
'count_reviewed' => 0,
'count_translated' => 0,
'count_pending' => 0,
))
->condition('state', TMGMT_JOB_ITEM_STATE_ACCEPTED)
->execute();
}
/**
* Create tmgmt_remote table to provide generic functionality for remote job
* mappings.
*/
function tmgmt_update_7010() {
db_create_table('tmgmt_remote', array(
'description' => 'TMGMT job remote mapping.',
'fields' => array(
'trid' => array(
'description' => 'The primary key.',
'type' => 'serial',
'not null' => TRUE,
),
'tjid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => '{tmgmt_job}.tjid foreign key',
),
'tjiid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => '{tmgmt_job_item}.tjjid foreign key',
),
'data_item_key' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Translation job data item key.',
),
'remote_identifier_1' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Custom remote identifier data.',
),
'remote_identifier_2' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Custom remote identifier data.',
),
'remote_identifier_3' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Custom remote identifier data.',
),
'remote_url' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Remote job url.',
),
'word_count' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Word count info provided by the remote service.',
),
'remote_data' => array(
'description' => 'Custom remote data.',
'type' => 'text',
'size' => 'big',
'serialize' => TRUE,
),
),
'primary key' => array('trid'),
'indexes' => array(
'tjid' => array('tjid'),
'tjiid' => array('tjiid'),
'remote_identifiers' => array('remote_identifier_1', 'remote_identifier_2', 'remote_identifier_3'),
),
));
}
/**
* Add uid field for {tmgmt_message} table.
*/
function tmgmt_update_7011() {
db_add_field('tmgmt_message', 'uid', array(
'description' => 'The identifier of the user who performed the action.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
));
}
/**
* Shortens remote_identifier_1/2 fields and recreates index for remote
* identifier fields to include only the first two.
*/
function tmgmt_update_7012() {
db_drop_index('tmgmt_remote', 'remote_identifiers');
db_change_field('tmgmt_remote', 'remote_identifier_1', 'remote_identifier_1', array(
'type' => 'varchar',
'length' => 127,
'not null' => TRUE,
'default' => '',
'description' => 'Custom remote identifier data.',
));
db_change_field('tmgmt_remote', 'remote_identifier_2', 'remote_identifier_2', array(
'type' => 'varchar',
'length' => 127,
'not null' => TRUE,
'default' => '',
'description' => 'Custom remote identifier data.',
));
db_add_index('tmgmt_remote', 'remote_identifiers', array('remote_identifier_1', 'remote_identifier_2'));
}
/**
* Shortens reference and label fields in {tmgmt_job} to length 255.
*
* Avoids issues with InnoDB and UTF-8 key limits.
*/
function tmgmt_update_7013() {
db_drop_index('tmgmt_job', 'reference');
db_change_field('tmgmt_job', 'reference', 'reference', array(
'description' => 'Remote identifier of this translation job.',
'type' => 'varchar',
'length' => 255,
));
db_change_field('tmgmt_job', 'label', 'label', array(
'description' => 'Optional user provided label of the job.',
'type' => 'varchar',
'length' => 255,
));
db_add_index('tmgmt_job', 'reference', array('reference'));
}
/**
* Add amount and currency fields for {tmgmt_remote} table.
*/
function tmgmt_update_7014() {
db_add_field('tmgmt_remote', 'amount', array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Amount charged for the remote translation job.',
));
db_add_field('tmgmt_remote', 'currency', array(
'type' => 'char',
'length' => 3,
'not null' => TRUE,
'default' => '',
'description' => 'Amount charged currency.',
));
}