5 private static $instance =
null;
7 private $infoXML =
null;
10 private $total_size = 0.0;
11 private $last_backup_time = 0;
21 if (!isset(self::$instance))
26 return self::$instance;
36 private function _getInformation($force =
false)
38 if ($this->init && !$force)
46 $web_service =
new CBitrixCloudBackupWebService();
47 $web_service->setTimeout(10);
48 $this->infoXML = $web_service->actionGetInformation();
50 catch (CBitrixCloudException $_)
55 $node = $this->infoXML->SelectNodes(
'/control/quota/allow');
58 $this->quota = \Bitrix\Main\Config\Ini::unformatInt($node->textContent());
61 $node = $this->infoXML->SelectNodes(
'/control/files');
64 $this->last_backup_time = 0;
65 $this->total_size = 0.0;
67 $nodeFiles = $node->elementsByName(
'file');
68 foreach ($nodeFiles as $nodeFile)
71 $size = \Bitrix\Main\Config\Ini::unformatInt($nodeFile->getAttribute(
'size'));
72 $name = $nodeFile->getAttribute(
'name');
73 $this->total_size += $size;
76 'FILE_SIZE' => (string)$size,
78 $time = strtotime(preg_replace(
'/^(\\d{4})(\\d\\d)(\\d\\d)_(\\d\\d)(\\d\\d)(\\d\\d)(.*)$/',
'\\1-\\2-\\3 \\4:\\5:\\6',
$name));
79 if (
$time > $this->last_backup_time)
81 $this->last_backup_time =
$time;
97 $this->_getInformation();
109 $this->_getInformation();
121 $this->_getInformation();
122 return $this->total_size;
133 $this->_getInformation();
134 return $this->last_backup_time;
146 private function _getBucket($operation, $check_word, $file_name)
148 if (!CModule::IncludeModule(
'clouds'))
153 $web_service =
new CBitrixCloudBackupWebService();
154 if ($operation ===
'write')
156 $obXML = $web_service->actionWriteFile($check_word, $file_name);
160 $obXML = $web_service->actionReadFile($check_word, $file_name);
163 $bucket_name = (is_object($node = $obXML->SelectNodes(
'/control/bucket/bucket_name'))) ? $node->textContent() :
'';
164 $bucket_location = (is_object($node = $obXML->SelectNodes(
'/control/bucket/bucket_location'))) ? $node->textContent() :
'';
165 $prefix = (is_object($node = $obXML->SelectNodes(
'/control/bucket/prefix'))) ? $node->textContent() :
'';
166 $access_key = (is_object($node = $obXML->SelectNodes(
'/control/bucket/access_key'))) ? $node->textContent() :
'';
167 $secret_key = (is_object($node = $obXML->SelectNodes(
'/control/bucket/secret_key'))) ? $node->textContent() :
'';
168 $session_token = (is_object($node = $obXML->SelectNodes(
'/control/bucket/session_token'))) ? $node->textContent() :
'';
169 $file_name = (is_object($node = $obXML->SelectNodes(
'/control/bucket/file_name'))) ? $node->textContent() :
'';
170 $service_id = (is_object($node = $obXML->SelectNodes(
'/control/bucket/bucket_service_id'))) ? $node->textContent() :
'';
172 return new CBitrixCloudBackupBucket(
195 return $this->_getBucket(
'read', $check_word, $file_name);
208 return $this->_getBucket(
'write', $check_word, $file_name);
232 $this->_getInformation();
234 foreach ($this->files as $arFile)
236 $arFiles[$arFile[
'FILE_NAME']] = $arFile[
'FILE_SIZE'];
257 'FILE_NAME' => $FILE_NAME,
258 'FILE_SIZE' => $FILE_SIZE,
283 $backup->loadFromOptions();
288 $backup->getQuota() <= 0
289 && $last_request_time_option->getIntegerValue() <= 0
292 $backup->_getInformation(
true);
293 $backup->saveToOptions();
294 $last_request_time_option->setStringValue((
string)time());
302 if ( $backup->getQuota() <= 0 )
310 $PROGRESS_FREE = 100;
311 $AVAIL = $backup->getQuota();
312 $ALLOWED = CFile::FormatSize($backup->getQuota(), 0);
313 $informerParams[
'ALERT'] =
true;
314 $MESS =
'<span class="adm-informer-strong-text">' .
GetMessage(
'BCL_BACKUP_AI_NO_FILES') .
'</span>';
315 if (
$USER->CanDoOperation(
'bitrixcloud_backup') &&
$USER->CanDoOperation(
'edit_php'))
317 $informerParams[
'FOOTER'] =
'<a href="/bitrix/admin/dump.php?lang=' . LANGUAGE_ID .
'">' .
GetMessage(
'BCL_BACKUP_AI_DO_BACKUP_STRONGLY') .
'</a>';
320 elseif ($backup->getLastTimeBackup() < (time() - 7 * 24 * 3600))
322 $AVAIL = $backup->getQuota() - $backup->getUsage();
328 $PROGRESS_FREE = round($AVAIL / $backup->getQuota() * 100);
329 $ALLOWED = CFile::FormatSize($backup->getQuota(), 0);
330 $informerParams[
'ALERT'] =
true;
333 'yesterday' =>
'yesterday',
335 ], $backup->getLastTimeBackup()) .
'.</span>';
336 if (
$USER->CanDoOperation(
'bitrixcloud_backup') &&
$USER->CanDoOperation(
'edit_php'))
338 $informerParams[
'FOOTER'] =
'<a href="/bitrix/admin/dump.php?lang=' . LANGUAGE_ID .
'">' .
GetMessage(
'BCL_BACKUP_AI_DO_BACKUP_STRONGLY') .
'</a>';
343 $AVAIL = $backup->getQuota() - $backup->getUsage();
349 $PROGRESS_FREE = round($AVAIL / $backup->getQuota() * 100);
350 $ALLOWED = CFile::FormatSize($backup->getQuota(), 0);
351 $informerParams[
'ALERT'] =
false;
354 'yesterday' =>
'yesterday',
356 ], $backup->getLastTimeBackup());
357 if (
$USER->CanDoOperation(
'bitrixcloud_backup') &&
$USER->CanDoOperation(
'edit_php'))
359 $informerParams[
'FOOTER'] =
'<a href="/bitrix/admin/dump.php?lang=' . LANGUAGE_ID .
'">' .
GetMessage(
'BCL_BACKUP_AI_DO_BACKUP') .
'</a>';
363 if (isset($informerParams[
'ALERT']))
365 $PROGRESS_FREE_BAR = $PROGRESS_FREE < 0 ? 0 : $PROGRESS_FREE;
366 $informerParams[
'HTML'] =
'
367 <div class="adm-informer-item-section">
368 <span class="adm-informer-item-l">
369 <span class="adm-informer-strong-text">' .
GetMessage(
'BCL_BACKUP_AI_USAGE_TOTAL') .
'</span> ' . $ALLOWED .
'
371 <span class="adm-informer-item-r">
372 <span class="adm-informer-strong-text">' .
GetMessage(
'BCL_BACKUP_AI_USAGE_AVAIL') .
'</span> ' . CFile::FormatSize($AVAIL, 0) .
'
375 <div class="adm-informer-status-bar-block" >
376 <div class="adm-informer-status-bar-indicator" style="width:' . (100 - $PROGRESS_FREE_BAR) .
'%; "></div>
377 <div class="adm-informer-status-bar-text">' . (100 - $PROGRESS_FREE) .
'%</div>
400 $web_service->actionAddBackupJob($secret_key,
$url,
$time, $weekdays);
405 return $e->getMessage();
421 $web_service->actionDeleteBackupJob();
426 return $e->getMessage();
435 $infoXML = $web_service->actionGetBackupJob();
439 return $e->getMessage();
443 $jobList = $infoXML->SelectNodes(
'/control/JobList');
444 if (is_object($jobList))
446 $jobEntries = $jobList->elementsByName(
'JobEntry');
447 foreach ($jobEntries as $jobEntry)
450 foreach ($jobEntry->children() as $field)
452 $name = $field->name();
453 $value = $field->textContent();
457 'URL' =>
$info[
'Url'],
458 'TIME' =>
$info[
'Time'],
459 'WEEK_DAYS' => explode(
',',
$info[
'WeekDays']),
460 'STATUS' =>
$info[
'Status'],
461 'FINISH_TIME' =>
$info[
'FinishTime'],
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)