Skip to content

Commit

Permalink
updating cache to use cache::delete and fixing the bug where adding a…
Browse files Browse the repository at this point in the history
… theme and making it active will break things
  • Loading branch information
dogmatic69 committed Feb 6, 2010
1 parent c496e70 commit 0c77710
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
27 changes: 20 additions & 7 deletions infinitas/management/controllers/themes_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ function admin_index() {

function admin_add() {
if (!empty($this->data)) {
if ($this->data['Theme']['active']) {
$this->Theme->_deactivateAll();
}

$this->Theme->create();
if ($this->Theme->saveAll($this->data)) {
$this->Session->setFlash('Your theme has been saved.');
Expand All @@ -46,6 +50,10 @@ function admin_edit($id = null) {
}

if (!empty($this->data)) {
if ($this->data['Theme']['active']) {
$this->Theme->_deactivateAll();
}

if ($this->Theme->save($this->data)) {
$this->Session->setFlash(__('Your theme has been saved.', true));
$this->redirect(array('action' => 'index'));
Expand All @@ -60,7 +68,12 @@ function admin_edit($id = null) {
}



/**
* Mass action.
*
* This overwrites the default toggle action so that other themes can
* be deactivated first as you should only have one active at a time.
*/
function admin_mass() {
$model = $this->modelNames[0];
$ids = $this->__massGetIds($this->data[$model]);
Expand All @@ -72,12 +85,12 @@ function admin_mass() {
$this->redirect($this->referer());
}

$this->$model->updateAll(
array(
$model.'.active' => '0'
)
);
return parent::__massActionToggle($ids);
if ($this->Theme->_deactivateAll()) {
return parent::__massActionToggle($ids);
}

$this->Session->setFlash(__('There was a problem deactivating the other theme', true));
$this->redirect($this->referer());
break;

default:
Expand Down
34 changes: 19 additions & 15 deletions infinitas/management/models/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class Theme extends ManagementAppModel {
* @return array $theme the current theme.
*/
function getCurrnetTheme(){

$theme = Cache::read('currentTheme');
$theme = Cache::read('current_theme', 'core');

if ($theme == false) {
$theme = $this->find(
Expand All @@ -44,33 +43,38 @@ function getCurrnetTheme(){
)
);
}
Cache::write('currentTheme', $theme, 'core');
Cache::write('current_theme', $theme, 'core');

return $theme;
}

/**
* Deactivate everything after making something else active
*/
* deactivate all themes.
*
* This is used before activating a theme to make sure that there is only
* ever one theme active.
*
* @return bool true on sucsess false if not.
*/
function _deactivateAll(){
return $this->updateAll(
array(
'Theme.active' => '0'
)
);
}

function afterSave($created) {
parent::afterSave($created);

$this->__clearCache();
Cache::delete('current_theme', 'core');
return true;
}

function afterDelete() {
parent::afterDelete();

$this->__clearCache();
return true;
}

function __clearCache() {
if (is_file(CACHE . 'core' . DS . 'current_theme')) {
unlink(CACHE . 'core' . DS . 'current_theme');
}

Cache::delete('current_theme', 'core');
return true;
}
}
Expand Down

0 comments on commit 0c77710

Please sign in to comment.