Elgg  Version 1.9
ElggUpgrade.php
Go to the documentation of this file.
1 <?php
19 class ElggUpgrade extends ElggObject {
20  private $requiredProperties = array(
21  'title',
22  'description',
23  'upgrade_url',
24  );
25 
32  public $_callable_egefps = 'elgg_get_entities_from_private_settings';
33 
39  public function initializeAttributes() {
40  parent::initializeAttributes();
41 
42  $this->attributes['subtype'] = 'elgg_upgrade';
43 
44  // unowned
45  $this->attributes['site_guid'] = 0;
46  $this->attributes['container_guid'] = 0;
47  $this->attributes['owner_guid'] = 0;
48 
49  $this->is_completed = 0;
50  }
51 
57  public function setCompleted() {
58  $this->setCompletedTime();
59  return $this->is_completed = true;
60  }
61 
67  public function isCompleted() {
68  return (bool) $this->is_completed;
69  }
70 
78  public function setPath($path) {
79  if (!$path) {
80  throw new InvalidArgumentException('Invalid value for URL path.');
81  }
82 
83  $path = ltrim($path, '/');
84 
85  if ($this->getUpgradeFromPath($path)) {
86  throw new InvalidArgumentException('Upgrade URL paths must be unique.');
87  }
88 
89  $this->upgrade_url = $path;
90  }
91 
97  public function getURL() {
98  return elgg_normalize_url($this->upgrade_url);
99  }
100 
107  public function setCompletedTime($time = null) {
108  if (!$time) {
109  $time = time();
110  }
111 
112  return $this->completed_time = $time;
113  }
114 
120  public function getCompletedTime() {
121  return $this->completed_time;
122  }
123 
130  public function save() {
131  foreach ($this->requiredProperties as $prop) {
132  if (!$this->$prop) {
133  throw new UnexpectedValueException("ElggUpgrade objects must have a value for the $prop property.");
134  }
135  }
136 
137  return parent::save();
138  }
139 
149  public function __set($name, $value) {
150  if (array_key_exists($name, $this->attributes)) {
151  parent::__set($name, $value);
152  } else {
153  $this->setPrivateSetting($name, $value);
154  }
155  }
156 
163  public function __get($name) {
164  // See if its in our base attribute
165  if (array_key_exists($name, $this->attributes)) {
166  return parent::__get($name);
167  }
168 
169  return $this->getPrivateSetting($name);
170  }
171 
178  public function getUpgradeFromPath($path) {
179  $path = ltrim($path, '/');
180 
181  if (!$path) {
182  return false;
183  }
184 
185  // test for full URL values (used at 1.9.0)
186  $options = array(
187  'type' => 'object',
188  'subtype' => 'elgg_upgrade',
189  'private_setting_name' => 'upgrade_url',
190  'private_setting_value' => elgg_normalize_url($path),
191  );
192  $upgrades = call_user_func($this->_callable_egefps, $options);
193  /* @var ElggUpgrade[] $upgrades */
194 
195  if ($upgrades) {
196  // replace URL with path (we can't use setPath due to recursion)
197  $upgrades[0]->upgrade_url = $path;
198  return $upgrades[0];
199  }
200 
201  $options['private_setting_value'] = $path;
202  $upgrades = call_user_func($this->_callable_egefps, $options);
203 
204  if ($upgrades) {
205  return $upgrades[0];
206  }
207 
208  return false;
209  }
210 }
isCompleted()
Has this upgrade completed?
Definition: ElggUpgrade.php:67
elgg_normalize_url($url)
Definition: output.php:290
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
__get($name)
Get an attribute or private setting value.
setPrivateSetting($name, $value)
Adds a private setting to this entity.
Definition: ElggEntity.php:669
getPrivateSetting($name)
Returns a private setting value.
Definition: ElggEntity.php:685
getURL()
Returns a normalized URL for the upgrade page.
Definition: ElggUpgrade.php:97
$value
Definition: longtext.php:29
setPath($path)
Sets an upgrade URL path.
Definition: ElggUpgrade.php:78
$upgrades
Lists pending upgrades.
Definition: upgrades.php:6
initializeAttributes()
Set subtype to upgrade.
Definition: ElggUpgrade.php:39
$options
Definition: index.php:14
getCompletedTime()
Gets the time when the upgrade completed.
getUpgradeFromPath($path)
Find an ElggUpgrade object by the unique URL path.
save()
Require an upgrade page.
__set($name, $value)
Set a value as private setting or attribute.
elgg river item elgg form comment save
Definition: components.php:242
setCompleted()
Mark this upgrade as completed.
Definition: ElggUpgrade.php:57
setCompletedTime($time=null)
Sets the timestamp for when the upgrade completed.
$path
Definition: invalid.php:17
Elgg Object.
Definition: ElggObject.php:22