32
32
$this->setId('webcam');
33
33
$this->setName($gallery->i18n('WebCam'));
34
34
$this->setDescription($gallery->i18n('Support periodically updated images like a webcam'));
35
$this->setVersion('1.0.0'); /* Update upgrade() function below too */
36
$this->setGroup('import', $this->translate('Import'));
35
$this->setVersion('1.0.3'); /* Update upgrade() function below too */
36
$this->setGroup('import', $gallery->i18n('Import'));
37
37
$this->setCallbacks('getSiteAdminViews');
38
$this->setRequiredCoreApi(array(6, 0));
39
$this->setRequiredModuleApi(array(2, 0));
38
$this->setRequiredCoreApi(array(7, 0));
39
$this->setRequiredModuleApi(array(3, 0));
74
74
WHERE [GalleryEntity::entityType] = \'GalleryLiveImage\'
75
75
AND [GalleryEntity::onLoadHandlers] IS NULL';
76
76
$ret = $storage->execute($query);
77
if ($ret->isError()) {
78
78
return $ret->wrap(__FILE__, __LINE__);
80
80
list ($ret, $handlers) = $storage->getFunctionSql('CONCAT',
81
81
array('[GalleryEntity::onLoadHandlers]', "'WebCam|'"));
82
if ($ret->isError()) {
83
83
return $ret->wrap(__FILE__, __LINE__);
85
85
$query = 'UPDATE [GalleryEntity]
106
109
case 'end of upgrade path':
110
return GalleryStatus::error(ERROR_BAD_PLUGIN, __FILE__, __LINE__,
111
sprintf('Unknown module version %s', $currentVersion));
113
return GalleryCoreApi::error(ERROR_BAD_PLUGIN, __FILE__, __LINE__,
114
sprintf('Unknown module version %s', $currentVersion));
115
return GalleryStatus::success();
122
125
$ret = GalleryCoreApi::registerFactoryImplementation(
123
126
'GalleryOnLoadHandler', 'WebCamModule', 'WebCam',
124
127
'modules/webcam/module.inc', 'webcam', null);
125
if ($ret->isError()) {
126
129
return $ret->wrap(__FILE__, __LINE__);
129
132
$ret = GalleryCoreApi::registerFactoryImplementation(
130
133
'ItemAddPlugin', 'ItemAddWebCam', 'ItemAddWebCam',
131
134
'modules/webcam/ItemAddWebCam.inc', 'webcam', null);
132
if ($ret->isError()) {
133
136
return $ret->wrap(__FILE__, __LINE__);
136
return GalleryStatus::success();
147
* @see GalleryModule::isRecommendedDuringInstall()
149
function isRecommendedDuringInstall() {
154
* @see GalleryModule::autoConfigure()
156
function autoConfigure() {
157
/* We don't require any special configuration */
158
return array(GalleryStatus::success(), true);
162
150
* @see GalleryModule::getSiteAdminViews()
164
152
function getSiteAdminViews() {
165
return array(GalleryStatus::success(),
166
154
array(array('name' => $this->translate('WebCam'),
167
155
'view' => 'webcam.WebCamSiteAdmin')));
171
159
* Check age and refresh from external source if needed..
173
161
function onLoad(&$item, $duringUpgrade) {
174
static $loop = array();
176
163
$id = $item->getId();
164
$loop = GalleryDataCache::containsKey("webcam:load-$id");
177
165
/* We don't want to refresh the external source during an upgrade */
178
166
if ($duringUpgrade) {
179
return GalleryStatus::success();
181
169
list ($ret, $duration) = $this->getParameter('duration');
182
if ($ret->isError()) {
183
171
return $ret->wrap(__FILE__, __LINE__);
185
if (time() - $item->getModificationTimestamp() > $duration && !isset($loop[$id])) {
173
if (time() - $item->getModificationTimestamp() > $duration && !$loop) {
186
174
/* Lock and refresh to ensure another request didn't just update image.. */
187
175
list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($id);
188
if ($ret->isError()) {
189
177
return $ret->wrap(__FILE__, __LINE__);
179
GalleryDataCache::put("webcam:load-$id", true);
192
180
list ($ret, $refresh) = $item->refresh();
193
if ($ret->isError()) {
194
182
GalleryCoreApi::releaseLocks($lockId);
195
183
return $ret->wrap(__FILE__, __LINE__);
203
$platform = $gallery->getPlatform();
191
$platform =& $gallery->getPlatform();
204
192
$tmpDir = $gallery->getConfig('data.gallery.tmp');
205
193
$tmpFile = $platform->tempnam($tmpDir, 'webcam');
206
194
list ($ret, $url) = $this->getParameter('imageUrl', $id);
207
if ($ret->isError()) {
208
196
GalleryCoreApi::releaseLocks($lockId);
209
197
return $ret->wrap(__FILE__, __LINE__);
212
200
list ($successfullyCopied, $response, $headers) =
213
201
GalleryCoreApi::fetchWebFile($url, $tmpFile);
214
if (!$successfullyCopied || strpos($response, '404 Not Found') !== false) {
202
if (!$successfullyCopied) {
215
203
/* Can't get the current image.. just keep what we have now */
217
205
list ($ret, $path) = $item->fetchPath();
218
if ($ret->isError()) {
219
207
GalleryCoreApi::releaseLocks($lockId);
220
208
return $ret->wrap(__FILE__, __LINE__);
210
/* Backup previous file */
211
$ret = $platform->copy($path, $tmpFile . '.bak');
213
GalleryCoreApi::releaseLocks($lockId);
214
return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__);
222
216
$ret = $platform->copy($tmpFile, $path);
224
218
GalleryCoreApi::releaseLocks($lockId);
225
return GalleryStatus::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__);
219
return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__);
227
221
$ret = $item->rescan();
228
if ($ret->isError()) {
229
GalleryCoreApi::releaseLocks($lockId);
230
return $ret->wrap(__FILE__, __LINE__);
232
$item->setOriginationTimestamp(time());
233
$ret = $item->save();
234
if ($ret->isError()) {
235
GalleryCoreApi::releaseLocks($lockId);
236
return $ret->wrap(__FILE__, __LINE__);
238
$ret = GalleryCoreApi::expireDerivativeTreeBySourceIds(array($id));
239
if ($ret->isError()) {
240
GalleryCoreApi::releaseLocks($lockId);
241
return $ret->wrap(__FILE__, __LINE__);
223
if (!($ret->getErrorCode() & ERROR_BAD_DATA_TYPE)) {
224
GalleryCoreApi::releaseLocks($lockId);
225
return $ret->wrap(__FILE__, __LINE__);
227
/* Problem with new file (maybe html response, not data file); rollback */
228
$platform->copy($tmpFile . '.bak', $path);
230
$item->setOriginationTimestamp(time());
231
$ret = $item->save();
233
GalleryCoreApi::releaseLocks($lockId);
234
return $ret->wrap(__FILE__, __LINE__);
236
$ret = GalleryCoreApi::expireDerivativeTreeBySourceIds(array($id));
238
GalleryCoreApi::releaseLocks($lockId);
239
return $ret->wrap(__FILE__, __LINE__);
242
@$platform->unlink($tmpFile . '.bak');
244
244
@$platform->unlink($tmpFile);
246
246
if (isset($lockId)) {
247
247
$ret = GalleryCoreApi::releaseLocks($lockId);
248
if ($ret->isError()) {
249
249
return $ret->wrap(__FILE__, __LINE__);
253
return GalleryStatus::success();