123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- <?php
- class ElggUpgrade extends \ElggObject {
- private $requiredProperties = array(
- 'title',
- 'description',
- 'upgrade_url',
- );
-
- public $_callable_egefps = 'elgg_get_entities_from_private_settings';
-
- public function initializeAttributes() {
- parent::initializeAttributes();
- $this->attributes['subtype'] = 'elgg_upgrade';
-
- $this->attributes['site_guid'] = 0;
- $this->attributes['container_guid'] = 0;
- $this->attributes['owner_guid'] = 0;
- $this->is_completed = 0;
- }
-
- public function setCompleted() {
- $this->setCompletedTime();
- return $this->is_completed = true;
- }
-
- public function isCompleted() {
- return (bool) $this->is_completed;
- }
-
- public function setPath($path) {
- if (!$path) {
- throw new InvalidArgumentException('Invalid value for URL path.');
- }
- $path = ltrim($path, '/');
- if ($this->getUpgradeFromPath($path)) {
- throw new InvalidArgumentException('Upgrade URL paths must be unique.');
- }
- $this->upgrade_url = $path;
- }
-
- public function getURL() {
- return elgg_normalize_url($this->upgrade_url);
- }
-
- public function setCompletedTime($time = null) {
- if (!$time) {
- $time = time();
- }
- return $this->completed_time = $time;
- }
-
- public function getCompletedTime() {
- return $this->completed_time;
- }
-
- public function save() {
- foreach ($this->requiredProperties as $prop) {
- if (!$this->$prop) {
- throw new UnexpectedValueException("ElggUpgrade objects must have a value for the $prop property.");
- }
- }
- return parent::save();
- }
-
- public function __set($name, $value) {
- if (array_key_exists($name, $this->attributes)) {
- parent::__set($name, $value);
- } else {
- $this->setPrivateSetting($name, $value);
- }
- }
-
- public function __get($name) {
-
- if (array_key_exists($name, $this->attributes)) {
- return parent::__get($name);
- }
- return $this->getPrivateSetting($name);
- }
-
- public function getUpgradeFromPath($path) {
- $path = ltrim($path, '/');
- if (!$path) {
- return false;
- }
-
- $options = array(
- 'type' => 'object',
- 'subtype' => 'elgg_upgrade',
- 'private_setting_name' => 'upgrade_url',
- 'private_setting_value' => elgg_normalize_url($path),
- );
- $upgrades = call_user_func($this->_callable_egefps, $options);
-
- if ($upgrades) {
-
- $upgrades[0]->upgrade_url = $path;
- return $upgrades[0];
- }
- $options['private_setting_value'] = $path;
- $upgrades = call_user_func($this->_callable_egefps, $options);
- if ($upgrades) {
- return $upgrades[0];
- }
- return false;
- }
- }
|