-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdmsync.module
More file actions
184 lines (162 loc) · 5.85 KB
/
dmsync.module
File metadata and controls
184 lines (162 loc) · 5.85 KB
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
<?php
/*
* @file
* Module file for dmsync.
*/
use DMWSPHP\DMWSConnection;
/*
* Implements hook_cron().
*/
function dmsync_cron() {
$queue = \Drupal::queue('dmsync_queue');
if ($queue->numberOfItems() == 0) {
/* acquire new data only if previous items have been proccessed */
dmsync_update_m();
}
}
function dmsync_update_m() {
//$config = \Drupal::config('dmsync.configuration');
$config = \Drupal::service('config.factory')->getEditable('dmsync.configuration');
if (!empty($config->get('username')) && !empty($config->get('password'))) {
try {
$conn = new DMWSConnection($config->get('username'), $config->get('password'), false);
$SchemaResource = $conn->getDefaultSchema();
$feed = (!empty($config->get("feed")))?$config->get("feed"):0;
$queue = \Drupal::queue('dmsync_queue');
$queue->createQueue();
//\Drupal::logger("dmsync")->notice("feed index: " . $feed);
switch($feed) {
case 0:
/* retrieve all PCI Records for active users */
$Users = $conn->getUsers();
$PCIRecords = $SchemaResource->getPCI();
foreach ($Users as $User) {
if ($User->isEnabled()) {
/* find PCI Record */
$Username = $User->getUsername();
foreach ($PCIRecords as $PCI) {
if ($PCI->getUsername() == $Username) {
$data = array(
'type' => 'user',
'title' => $PCI->getPrefix() . " " . $PCI->getFirstName() . " " . $PCI->getMiddleName() . " " . $PCI->getLastName(),
'username' => $PCI->getUsername(),
'userid' => $PCI->getUserId(),
'srank' => $PCI->getSRank(),
'roomnum' => $PCI->getRoomNumber(),
'prefix' => $PCI->getPrefix(),
'mname' => $PCI->getMiddleName(),
'lname' => $PCI->getLastName(),
'fname' => $PCI->getFirstName(),
'expertise' => $PCI->getExpertise(),
'building' => $PCI->getBuilding(),
'bio' => $PCI->getBio(),
'email' => $PCI->getEmail(),
'ophone' => $PCI->getOPhone(),
);
$queue->createItem($data);
}
}
}
}
break;
case 1:
$IntellcontRecords = $SchemaResource->getIntellcont();
foreach ($IntellcontRecords as $IntellcontRecord) {
/* check publication has title */
if ($IntellcontRecord->getTitle() && !empty($IntellcontRecord->getTitle())) {
$data = array(
'type' => 'publication',
'title' => substr($IntellcontRecord->getTitle(), 0, 255),
'abstract' => $IntellcontRecord->getAbstract(),
'class' => $IntellcontRecord->getClassification(),
'contype' => $IntellcontRecord->getConType(),
'id' => $IntellcontRecord->getId(),
'isbn' => $IntellcontRecord->getISBN(),
'issue' => $IntellcontRecord->getIssue(),
'pagenum' => $IntellcontRecord->getPageNum(),
'pub_end' => (!empty($IntellcontRecord->getPubEnd()))?(new \DateTime($IntellcontRecord->getPubEnd()))->format('Y-m-d\TH:i:s'):'', /* process pub_end value (ie. 2017-01-01T01:00:00)*/
'publicavail' => $IntellcontRecord->getPublicAvail(),
'publisher' => $IntellcontRecord->getPublisher(),
'refereed' => $IntellcontRecord->getRefereed(),
'status' => $IntellcontRecord->getStatus(),
'volume' => $IntellcontRecord->getVolume(),
);
$queue->createItem($data);
}
}
break;
case 2:
$IntellcontRecords = $SchemaResource->getIntellcont();
foreach ($IntellcontRecords as $IntellcontRecord) {
/* check publication has title */
if ($IntellcontRecord->getTitle() && !empty($IntellcontRecord->getTitle())) {
$Authors = $IntellcontRecord->getAuthors();
foreach ($Authors as $Author) {
$data = array(
'type' => 'author',
'title' => $Author->getID(),
'publication' => $IntellcontRecord->getId(),
'user' => $Author->getFacultyName(),
'role' => $Author->getRole(),
);
$queue->createItem($data);
}
}
}
break;
case 3:
$EducationRecords = $SchemaResource->getEducation();
foreach ($EducationRecords as $EducationRecord) {
$data = array(
'type' => 'education',
'id' => $EducationRecord->getId(),
'user' => $EducationRecord->getUserId(),
'degree' => $EducationRecord->getDeg(),
'school' => $EducationRecord->getSchool(),
'major' => $EducationRecord->getMajor(),
'yr_comp' => $EducationRecord->getYrComp(),
);
$queue->createItem($data);
}
break;
case 4:
$ResearchRecords = $SchemaResource->getResearch();
foreach ($ResearchRecords as $ResearchRecord) {
$data = array(
'type' => 'research',
'user' => $ResearchRecord->getUserId(),
'id' => $ResearchRecord->getId(),
'desc' => $ResearchRecord->getDesc(),
);
$queue->createItem($data);
}
break;
case 5:
$AwardRecords = $SchemaResource->getAwards();
foreach ($AwardRecords as $AwardRecord) {
$data = array(
'type' => 'award',
'user' => $AwardRecord->getUserId(),
'id' => $AwardRecord->getId(),
'name' => $AwardRecord->getName(),
'desc' => $AwardRecord->getDesc(),
'org' => $AwardRecord->getOrg(),
'scope' => $AwardRecord->getScope(),
'year' => $AwardRecord->getDTYDate(),
);
$queue->createItem($data);
}
break;
default:
break;
}
$feed = ($feed + 1) % 6;
$config->set("feed", $feed);
$config->save();
} catch (\Exception $e) {
\Drupal::logger('dmsync')->error($e);
}
} else {
\Drupal::logger('dmsync')->error("Module not yet configured.");
}
}