| 52 |
$this->group_name = $group_types[$this->grouptype]; |
$this->group_name = $group_types[$this->grouptype]; |
| 53 |
} |
} |
| 54 |
|
|
| 55 |
protected function load_all_blueprints() { |
protected function loadAllBlueprints() { |
| 56 |
$blueprint_type = preg_replace('/bundle/', 'blueprint', get_class($this)); |
$blueprint_type = preg_replace('/bundle/', 'blueprint', get_class($this)); |
| 57 |
$blueprints = db_query("SELECT bpid FROM {og_blueprint} WHERE vid = %d", $this->vid); |
$blueprints = db_query("SELECT bpid FROM {og_blueprint} WHERE vid = %d", $this->vid); |
| 58 |
while ($blueprint = db_fetch_array($blueprints)) { |
while ($blueprint = db_fetch_array($blueprints)) { |
| 60 |
} |
} |
| 61 |
} |
} |
| 62 |
|
|
| 63 |
public function sort_for_display() { |
public function sortForDisplay() { |
| 64 |
uasort($this->blueprints, 'og_blueprints_sort_bundle'); |
uasort($this->blueprints, 'og_blueprints_sort_bundle'); |
| 65 |
} |
} |
| 66 |
|
|
| 67 |
public function increment_bid_version() { |
public function incrementBundleVersion() { |
| 68 |
db_query("INSERT INTO {og_bundle_revision} (bid) VALUES (%d)", $this->bid); |
db_query("INSERT INTO {og_bundle_revision} (bid) VALUES (%d)", $this->bid); |
| 69 |
$this->vid = db_result(db_query("SELECT vid FROM {og_bundle_revision} WHERE bid = %d ORDER BY vid DESC LIMIT 1", $this->bid)); |
$this->vid = db_result(db_query("SELECT vid FROM {og_bundle_revision} WHERE bid = %d ORDER BY vid DESC LIMIT 1", $this->bid)); |
| 70 |
db_query("UPDATE {og_bundle} SET vid = %d WHERE bid = %d", $this->vid, $this->bid); |
db_query("UPDATE {og_bundle} SET vid = %d WHERE bid = %d", $this->vid, $this->bid); |
| 129 |
$this->did = $display->did; |
$this->did = $display->did; |
| 130 |
} |
} |
| 131 |
|
|
| 132 |
private function write_to_db($op, $args) { |
private function dbWrite($op, $args) { |
| 133 |
$args = og_blueprints_query_fields($args); |
$args = og_blueprints_query_fields($args); |
| 134 |
switch ($op) { |
switch ($op) { |
| 135 |
case 'update': |
case 'update': |
| 163 |
switch ($method) { |
switch ($method) { |
| 164 |
case 'propagate': |
case 'propagate': |
| 165 |
case 'save': |
case 'save': |
| 166 |
$this->write_to_db('update', !empty($args) ? $args : array('bid', 'vid', 'bpid', 'did', 'linked', 'enabled', 'published', 'default_page', 'page_title', 'show_blocks', 'path', 'weight')); |
$this->dbWrite('update', !empty($args) ? $args : array('bid', 'vid', 'bpid', 'did', 'linked', 'enabled', 'published', 'default_page', 'page_title', 'show_blocks', 'path', 'weight')); |
| 167 |
break; |
break; |
| 168 |
|
|
| 169 |
case 'propagate': |
case 'propagate': |
| 170 |
$result = db_query("SELECT vid, bid FROM {og_bundle}"); |
$result = db_query("SELECT vid, bid FROM {og_bundle}"); |
| 171 |
while ($row = db_fetch_array($result)) { |
while ($row = db_fetch_array($result)) { |
| 172 |
list ($this->vid, $this->bid) = array_values($row); |
list ($this->vid, $this->bid) = array_values($row); |
| 173 |
$this->write_to_db('update', $args); |
$this->dbWrite('update', $args); |
| 174 |
} |
} |
| 175 |
break; |
break; |
| 176 |
|
|
| 184 |
} |
} |
| 185 |
|
|
| 186 |
protected function insert($args = NULL) { |
protected function insert($args = NULL) { |
| 187 |
$this->write_to_db('insert', !is_null($args) ? $args : array('bid', 'vid', 'bpid', 'bpname', 'did', 'linked', 'enabled', 'published', 'default_page', 'page_title', 'show_blocks', 'path')); |
$this->dbWrite('insert', !is_null($args) ? $args : array('bid', 'vid', 'bpid', 'bpname', 'did', 'linked', 'enabled', 'published', 'default_page', 'page_title', 'show_blocks', 'path')); |
| 188 |
} |
} |
| 189 |
|
|
| 190 |
// magic method for snagging certain requested members on demand |
// magic method for snagging certain requested members on demand |
| 216 |
function __construct() { |
function __construct() { |
| 217 |
$this->grouptype = 'master'; |
$this->grouptype = 'master'; |
| 218 |
parent::__construct(); |
parent::__construct(); |
| 219 |
$this->load_all_blueprints(); |
$this->loadAllBlueprints(); |
| 220 |
$this->sort_for_display(); |
$this->sortForDisplay(); |
| 221 |
} |
} |
| 222 |
|
|
| 223 |
public function dashboard() { |
public function dashboard() { |
| 251 |
function __construct($grouptype) { |
function __construct($grouptype) { |
| 252 |
$this->grouptype = $grouptype; |
$this->grouptype = $grouptype; |
| 253 |
parent::__construct(); |
parent::__construct(); |
| 254 |
$this->load_all_blueprints(); |
$this->loadAllBlueprints(); |
| 255 |
$this->sort_for_display(); |
$this->sortForDisplay(); |
| 256 |
} |
} |
| 257 |
|
|
| 258 |
public function dashboard() { |
public function dashboard() { |
| 289 |
$this->grouptype = $grouptype; |
$this->grouptype = $grouptype; |
| 290 |
$this->release_name = $release_name; |
$this->release_name = $release_name; |
| 291 |
parent::__construct(); |
parent::__construct(); |
| 292 |
$this->load_all_blueprints(); |
$this->loadAllBlueprints(); |
| 293 |
$this->make_release(); |
$this->makeRelease(); |
| 294 |
} |
} |
| 295 |
|
|
| 296 |
private function make_release() { |
private function makeRelease() { |
| 297 |
db_query("UPDATE {og_bundle_revision} SET release_id = %d , release_name = '%s' , timestamp = %d WHERE vid = %d", ++$this->release_id, $this->release_name, time(), $this->vid); |
db_query("UPDATE {og_bundle_revision} SET release_id = %d , release_name = '%s' , timestamp = %d WHERE vid = %d", ++$this->release_id, $this->release_name, time(), $this->vid); |
| 298 |
$this->increment_bid_version(); |
$this->incrementBundleVersion(); |
| 299 |
db_query("UPDATE {og_bundle} SET release_id = %d WHERE bid = %d", $this->release_id, $this->bid); |
db_query("UPDATE {og_bundle} SET release_id = %d WHERE bid = %d", $this->release_id, $this->bid); |
| 300 |
foreach ($this->blueprints as $bpid => &$blueprint) { |
foreach ($this->blueprints as $bpid => &$blueprint) { |
| 301 |
$blueprint->new_version($this->vid); |
$blueprint->newVersion($this->vid); |
| 302 |
if ($this->bid != 1) { |
if ($this->bid != 1) { |
| 303 |
$blueprint->update_dids(); |
$blueprint->updateDids(); |
| 304 |
} |
} |
| 305 |
} |
} |
| 306 |
if ($this->bid == 1) { |
if ($this->bid == 1) { |
| 307 |
$this->master_release_updates(); |
$this->masterReleaseUpdates(); |
| 308 |
} |
} |
| 309 |
} |
} |
| 310 |
|
|
| 311 |
private function master_release_updates() { |
private function masterReleaseUpdates() { |
| 312 |
foreach (db_fetch_array(db_query("SELECT grouptype FROM {og_bundle} WHERE bid <> 1")) as $group_type) { |
foreach (db_fetch_array(db_query("SELECT grouptype FROM {og_bundle} WHERE bid <> 1")) as $group_type) { |
| 313 |
$bundle = new og_bundle_typed($group_type); |
$bundle = new og_bundle_typed($group_type); |
| 314 |
$bundle->load_all_blueprints(); |
$bundle->loadAllBlueprints(); |
| 315 |
db_query("UPDATE {og_bundle_revision} SET release_id = %d , release_name = '%s' , timestamp = %d WHERE vid = (SELECT vid FROM {og_bundle} WHERE bid = %d)", ++$bundle->release_id, $this->release_name, time(), $bundle->bid); |
db_query("UPDATE {og_bundle_revision} SET release_id = %d , release_name = '%s' , timestamp = %d WHERE vid = (SELECT vid FROM {og_bundle} WHERE bid = %d)", ++$bundle->release_id, $this->release_name, time(), $bundle->bid); |
| 316 |
$this->increment_bid_version(); |
$this->incrementBundleVersion(); |
| 317 |
db_query("UPDATE {og_bundle} SET release_id = %d WHERE bid = %d", $this->release_id, $this->bid); |
db_query("UPDATE {og_bundle} SET release_id = %d WHERE bid = %d", $this->release_id, $this->bid); |
| 318 |
foreach ($bundle->blueprints as $bpid => &$blueprint) { |
foreach ($bundle->blueprints as $bpid => &$blueprint) { |
| 319 |
$blueprint->vid = $bundle->vid; |
$blueprint->vid = $bundle->vid; |
| 327 |
class og_blueprint_new_release extends og_blueprint { |
class og_blueprint_new_release extends og_blueprint { |
| 328 |
private $old_did; |
private $old_did; |
| 329 |
|
|
| 330 |
public function new_version($vid) { // very carefully, specifically ordered function. whew! |
public function newVersion($vid) { // very carefully, specifically ordered function. whew! |
| 331 |
$this->old_did = $this->did; |
$this->old_did = $this->did; |
| 332 |
$this->export(); |
$this->export(); |
| 333 |
$this->vid = $vid; |
$this->vid = $vid; |
| 334 |
$this->insert(); |
$this->insert(); |
| 335 |
} |
} |
| 336 |
|
|
| 337 |
public function update_dids() { |
public function updateDids() { |
| 338 |
if ($this->linked) { |
if ($this->linked) { |
| 339 |
db_query("UPDATE {og_blueprint} SET did = %d WHERE did = %d AND vid <> %d", $this->did, $this->old_did, $this->vid); |
db_query("UPDATE {og_blueprint} SET did = %d WHERE did = %d AND vid <> %d", $this->did, $this->old_did, $this->vid); |
| 340 |
} |
} |
| 350 |
function __construct($group_type, $release_id) { |
function __construct($group_type, $release_id) { |
| 351 |
$this->grouptype = $group_type; |
$this->grouptype = $group_type; |
| 352 |
$this->release_id = $release_id; |
$this->release_id = $release_id; |
| 353 |
list($this->bid, $this->vid) = array_values(db_fetch_array(db_query("SELECT b.bid, r.vid FROM {og_bundle} AS b INNER JOIN {og_bundle_revision} AS r ON b.bid = r.bid WHERE b.grouptype = '%s' AND r.release_id = %d", $this->grouptype, $this->release_id))); |
if ($result = db_query("SELECT b.bid, r.vid FROM {og_bundle} AS b INNER JOIN {og_bundle_revision} AS r ON b.bid = r.bid WHERE b.grouptype = '%s' AND r.release_id = %d", $this->grouptype, $this->release_id)) { |
| 354 |
$this->load_all_blueprints(); |
list($this->bid, $this->vid) = array_values(db_fetch_array($result)); |
| 355 |
|
} |
| 356 |
|
$this->loadAllBlueprints(); |
| 357 |
$this->blueprints = array_filter($this->blueprints, array($this, 'filter_disabled')); // TODO should this be here? probably. |
$this->blueprints = array_filter($this->blueprints, array($this, 'filter_disabled')); // TODO should this be here? probably. |
| 358 |
} |
} |
| 359 |
|
|
| 360 |
protected function filter_disabled($item) { |
protected function filterDisabled($item) { |
| 361 |
return $item->enabled == 1; |
return $item->enabled == 1; |
| 362 |
} |
} |
| 363 |
} |
} |
| 395 |
*/ |
*/ |
| 396 |
public function instantiate() { |
public function instantiate() { |
| 397 |
foreach ($this->blueprints as $bpid => $blueprint) { |
foreach ($this->blueprints as $bpid => $blueprint) { |
| 398 |
$blueprint->build_display($this->nid); |
$blueprint->buildDisplay($this->nid); |
| 399 |
} |
} |
| 400 |
} |
} |
| 401 |
} |
} |
| 403 |
class og_blueprint_instantiator extends og_blueprint_release { |
class og_blueprint_instantiator extends og_blueprint_release { |
| 404 |
public $nid; |
public $nid; |
| 405 |
|
|
| 406 |
public function build_display ($nid) { |
public function buildDisplay ($nid) { |
| 407 |
$fields = og_blueprints_query_fields(array('nid', 'did', 'published', 'page_title', 'path', 'default_page', 'show_blocks', 'weight')); |
$fields = og_blueprints_query_fields(array('nid', 'did', 'published', 'page_title', 'path', 'default_page', 'show_blocks', 'weight')); |
| 408 |
$this->nid = $nid; |
$this->nid = $nid; |
| 409 |
$this->export(); |
$this->export(); |
| 445 |
function __construct($group_type) { |
function __construct($group_type) { |
| 446 |
$this->grouptype = 'master'; |
$this->grouptype = 'master'; |
| 447 |
parent::__construct(); |
parent::__construct(); |
| 448 |
$this->load_all_blueprints(); |
$this->loadAllBlueprints(); |
| 449 |
$this->grouptype = $group_type; |
$this->grouptype = $group_type; |
| 450 |
$this->orphaned_bids = variable_get('og_blueprints_orphaned_bids', array()); |
$this->orphaned_bids = variable_get('og_blueprints_orphaned_bids', array()); |
| 451 |
} |
} |
| 452 |
|
|
| 453 |
public function create() { |
public function create() { |
| 454 |
if (isset($this->orphaned_bids[$this->grouptype])) { |
if (isset($this->orphaned_bids[$this->grouptype])) { |
| 455 |
$this->restore(); |
$this->_restore(); |
| 456 |
} |
} |
| 457 |
else { |
else { |
| 458 |
$this->add_new(); |
$this->_new(); |
| 459 |
} |
} |
| 460 |
} |
} |
| 461 |
|
|
| 462 |
protected function add_new() { |
protected function _new() { |
| 463 |
// FIXME slightly hacky way of preventing there from being duplicate names. this needs to throw an error that |
// FIXME slightly hacky way of preventing there from being duplicate names. this needs to throw an error that |
| 464 |
// can be caught and then run an update and fix it appropriately. |
// can be caught and then run an update and fix it appropriately. |
| 465 |
if (!db_result(db_query("SELECT bid FROM {og_bundle} WHERE grouptype = '%s'", $this->grouptype))) { |
if (!db_result(db_query("SELECT bid FROM {og_bundle} WHERE grouptype = '%s'", $this->grouptype))) { |
| 466 |
$this->bid = db_next_id("{og_bundle}_bid"); |
$this->bid = db_next_id("{og_bundle}_bid"); |
| 467 |
db_query("INSERT INTO {og_bundle} (bid, grouptype) VALUES (%d, '%s')", $this->bid, $this->grouptype); |
db_query("INSERT INTO {og_bundle} (bid, grouptype) VALUES (%d, '%s')", $this->bid, $this->grouptype); |
| 468 |
$this->increment_bid_version(); |
$this->incrementBundleVersion(); |
| 469 |
foreach ($this->blueprints as &$blueprint) { |
foreach ($this->blueprints as &$blueprint) { |
| 470 |
$blueprint->clone_from_master($this->bid, $this->vid); |
$blueprint->cloneFromMaster($this->bid, $this->vid); |
| 471 |
} |
} |
| 472 |
} |
} |
| 473 |
} |
} |
| 479 |
* FIXME this is ugly at the moment - need to figure out if there's a good & reasonable way to differentiate |
* FIXME this is ugly at the moment - need to figure out if there's a good & reasonable way to differentiate |
| 480 |
* between the actions that should be taken depending on what's in $orphaned_groups['grouptype']['op'] |
* between the actions that should be taken depending on what's in $orphaned_groups['grouptype']['op'] |
| 481 |
*/ |
*/ |
| 482 |
protected function restore() { |
protected function _restore() { |
| 483 |
// if ($this->orphaned_bids[$this->grouptype]['op'] == 'unset_as_group') { |
// if ($this->orphaned_bids[$this->grouptype]['op'] == 'unset_as_group') { |
| 484 |
$this->bid = $this->orphaned_bids[$this->grouptype]['bid']; |
$this->bid = $this->orphaned_bids[$this->grouptype]['bid']; |
| 485 |
db_query("INSERT INTO {og_bundle} (bid, grouptype) VALUES (%d, '%s')", $this->bid, $this->grouptype); |
db_query("INSERT INTO {og_bundle} (bid, grouptype) VALUES (%d, '%s')", $this->bid, $this->grouptype); |
| 492 |
|
|
| 493 |
class og_blueprint_type_creator extends og_blueprint { |
class og_blueprint_type_creator extends og_blueprint { |
| 494 |
|
|
| 495 |
function clone_from_master($bid, $vid) { |
function cloneFromMaster($bid, $vid) { |
| 496 |
list($this->bid, $this->vid) = array($bid, $vid); |
list($this->bid, $this->vid) = array($bid, $vid); |
| 497 |
$this->insert(); |
$this->insert(); |
| 498 |
} |
} |