Skip to content

Commit

Permalink
fixing code so tests will pass
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmatic69 committed Aug 23, 2012
1 parent bdda874 commit eec25c0
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 96 deletions.
2 changes: 1 addition & 1 deletion Config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function configureCache($cacheDetails) {

if(Configure::read('Cache.engine') == 'Libs.NamespaceFile') {
if(!is_dir(CACHE . $folder)) {
$Folder = new Folder(CACHE . $folder, true, 755);
$Folder = new Folder(CACHE . $folder, true, 0755);
}
}

Expand Down
13 changes: 12 additions & 1 deletion Core/Contents/Lib/ContentsEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,18 @@ public function onSiteMapRebuild($event) {
'change_frequency' => $frequency
);

$categories = $Category->find('list', array('fields' => array('GlobalCategory.id', 'GlobalCategory.slug')));
$categories = ClassRegistry::init('Contents.GlobalContent')->find(
'list',
array(
'fields' => array(
'GlobalContent.foreign_key',
'GlobalContent.slug'
),
'conditions' => array(
'GlobalContent.model' => 'Contents.GlobalCategory'
)
)
);
foreach($categories as $category) {
$return[] = array(
'url' => Router::url(
Expand Down
10 changes: 3 additions & 7 deletions Core/Filemanager/Model/Behavior/UploadBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ public function setup(&$Model, $config = array()) {
$this->settings[$Model->alias] = array();

foreach ($config as $field => $options) {
if(!$Model->hasField($field)) {
throw new InvalidArgumentException(sprintf('Model "%s" does not contain the field "%s"', $Model->name, $field));
if (is_int($field)) {
$field = $options;
$options = array();
}

$this->_setupField($Model, $field, $options);
Expand Down Expand Up @@ -166,11 +167,6 @@ protected function _emptyFilePath() {
* @author Jose Diaz-Gonzalez
*/
public function _setupField(&$model, $field, $options) {
if (is_int($field)) {
$field = $options;
$options = array();
}

$this->defaults['rootDir'] = ROOT . DS . APP_DIR . DS;
if (!isset($this->settings[$model->alias][$field])) {
$options = array_merge($this->defaults, (array) $options);
Expand Down
8 changes: 5 additions & 3 deletions Core/Libs/Console/Command/Task/ProgressBarTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function start($total, $clear = true) {
$this->total = $total;
$this->done = 0;
$this->startTime = time();
$this->_setTerminalWidth();
$this->setTerminalWidth();
if ($clear) {
$this->out('', 1);
}
Expand Down Expand Up @@ -242,10 +242,12 @@ protected function _niceRemaining() {
*
* @TODO can you get windows to tell you the size of the terminal?
* @param mixed $width null
*
* @return void
* @access protected
*
* @access public
*/
protected function _setTerminalWidth($width = null) {
public function setTerminalWidth($width = null) {
if ($width === null) {
if (DS === '/') {
$width = `tput cols`;
Expand Down
96 changes: 47 additions & 49 deletions Core/Libs/Model/Behavior/InfiniTreeBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class InfiniTreeBehavior extends TreeBehavior {
* @return void
* @access public
*/
public function setup($Model, $config = array()) {
public function setup(Model $Model, $config = array()) {

$defaults = array(
'scopeField' => false,
Expand Down Expand Up @@ -61,7 +61,7 @@ public function setup($Model, $config = array()) {
* @return boolean true on success, false on failure
* @access public
*/
public function afterSave($Model, $created) {
public function afterSave(Model $Model, $created) {
if($this->scoped($Model)) {
$this->__setScope($Model, $Model->data[$Model->alias]);
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public function afterSave($Model, $created) {
* @return boolean true to continue, false to abort the delete
* @access public
*/
public function beforeDelete($Model) {
public function beforeDelete(Model $Model) {
if($this->scoped($Model)) {
$this->__setScope($Model);
}
Expand All @@ -115,15 +115,15 @@ public function beforeDelete($Model) {
* @return boolean true to continue, false to abort the delete
* @access public
*/
public function afterDelete($Model) {
public function afterDelete(Model $Model) {
if($this->counterCacheEnabled($Model) && $this->__parentId) {
$this->updateTreeCounterCache($Model, $this->__parentId);
}

return parent::afterDelete($Model);
}

public function beforeSave($Model) {
public function beforeSave(Model $Model) {
if($this->scoped($Model)) {
if(!$Model->id || $Model->id && array_key_exists($this->settings[$Model->alias]['parent'], $Model->data)) {
if(!$this->__setScope($Model, $Model->data[$Model->alias], true)) {
Expand Down Expand Up @@ -159,7 +159,7 @@ public function beforeSave($Model) {
* @access public
* @link http://book.cakephp.org/view/1347/Counting-children
*/
public function childcount($Model, $id = null, $direct = false) {
public function childcount(Model $Model, $id = null, $direct = false) {
if($this->scoped($Model)) {
if(empty($id)) {
return false;
Expand Down Expand Up @@ -196,7 +196,7 @@ public function childcount($Model, $id = null, $direct = false) {
* @access public
* @link http://book.cakephp.org/view/1346/Children
*/
public function children($Model, $id = null, $direct = false, $fields = null, $order = null, $limit = null, $page = 1, $recursive = null) {
public function children(Model $Model, $id = null, $direct = false, $fields = null, $order = null, $limit = null, $page = 1, $recursive = null) {
if($this->scoped($Model)) {
if(empty($id)) {
return false;
Expand All @@ -223,7 +223,7 @@ public function children($Model, $id = null, $direct = false, $fields = null, $o
* @access public
* @link http://book.cakephp.org/view/1348/generateTreeList
*/
public function generateTreeList($Model, $conditions = null, $keyPath = null, $valuePath = null, $spacer = '_', $recursive = null) {
public function generateTreeList(Model $Model, $conditions = null, $keyPath = null, $valuePath = null, $spacer = '_', $recursive = null) {
if($this->scoped($Model)) {
$this->__setScope($Model, $conditions);
}
Expand All @@ -244,9 +244,9 @@ public function generateTreeList($Model, $conditions = null, $keyPath = null, $v
* @param integer $recursive The number of levels deep to fetch associated records
* @return array Array of nodes from top most parent to current node
* @access public
* @link http://book.cakephp.org/view/1350/getpath
* @link http://book.cakephp.org/view/1350/getPath
*/
public function getpath($Model, $id = null, $fields = null, $recursive = null) {
public function getPath(Model $Model, $id = null, $fields = null, $recursive = null) {
if($this->scoped($Model)) {
$id = $this->__setScopeFromId($Model, $id);

Expand All @@ -255,7 +255,7 @@ public function getpath($Model, $id = null, $fields = null, $recursive = null) {
}
}

return parent::getpath($Model, $id, $fields, $recursive);
return parent::getPath($Model, $id, $fields, $recursive);
}

/**
Expand All @@ -270,7 +270,7 @@ public function getpath($Model, $id = null, $fields = null, $recursive = null) {
* @access public
* @link http://book.cakephp.org/view/1352/moveDown
*/
public function movedown($Model, $id = null, $number = 1) {
public function movedown(Model $Model, $id = null, $number = 1) {
if($this->scoped($Model)) {
$id = $this->__setScopeFromId($Model, $id);

Expand All @@ -294,7 +294,7 @@ public function movedown($Model, $id = null, $number = 1) {
* @access public
* @link http://book.cakephp.org/view/1353/moveUp
*/
public function moveup($Model, $id = null, $number = 1) {
public function moveup(Model $Model, $id = null, $number = 1) {
if($this->scoped($Model)) {
if(empty($id)) {
return false;
Expand Down Expand Up @@ -324,7 +324,7 @@ public function moveup($Model, $id = null, $number = 1) {
* @access public
* @link http://book.cakephp.org/view/1628/Recover
*/
public function recover($Model, $mode = 'parent', $missingParentAction = null, $scope = null) {
public function recover(Model $Model, $mode = 'parent', $missingParentAction = null, $scope = null) {
if($this->scoped($Model)) {
if(empty($scope)) {
return false;
Expand Down Expand Up @@ -360,7 +360,7 @@ public function recover($Model, $mode = 'parent', $missingParentAction = null, $
* @link http://book.cakephp.org/view/1355/reorder
* @link http://book.cakephp.org/view/1629/Reorder
*/
public function reorder($Model, $options = array()) {
public function reorder(Model $Model, $options = array()) {
if($this->scoped($Model)) {
if(empty($options[$Model->primaryKey]) && empty($options['scope'])) {
return false;
Expand Down Expand Up @@ -396,7 +396,7 @@ public function reorder($Model, $options = array()) {
* @access public
* @link http://book.cakephp.org/view/1354/removeFromTree
*/
public function removefromtree($Model, $id = null, $delete = false, $scopeField = null) {
public function removefromtree(Model $Model, $id = null, $delete = false, $scopeField = null) {
if($this->scoped($Model)) {
$id = $this->__setScopeFromId($Model, $id);

Expand All @@ -421,7 +421,7 @@ public function removefromtree($Model, $id = null, $delete = false, $scopeField
* @link http://book.cakephp.org/view/1630/Verify
*/

public function verify($Model, $scope = null) {
public function verify(Model $Model, $scope = null) {
if($this->scoped($Model)) {
$this->__setScope($Model, $scope);
}
Expand Down Expand Up @@ -501,7 +501,7 @@ public function verify($Model, $scope = null) {
* @return mixed true if succesfully saved or false on error
* @access public
*/
public function treeSave($Model, $data = array(), $options = array()) {
public function treeSave(Model $Model, $data = array(), $options = array()) {
if(empty($data)) {
return false;
}
Expand All @@ -525,7 +525,7 @@ public function treeSave($Model, $data = array(), $options = array()) {
return false;
}

public function scoped($Model) {
public function scoped(Model $Model) {
return !empty($this->settings[$Model->alias]['scopeField']);
}

Expand All @@ -539,10 +539,11 @@ public function scoped($Model) {
*
* @return Array model data
*/
public function updateTreeCounterCache($Model, $id=null) {
public function updateTreeCounterCache(Model $Model, $id=null) {
if(is_null($id)) {
$id = $Model->id;
}

if(!$id) {
return false;
}
Expand All @@ -557,30 +558,21 @@ public function updateTreeCounterCache($Model, $id=null) {

$counts = array();

//Calculate children count
if($this->settings[$Model->alias]['counterCache']) {
//Take a shortcut if we dont do any extra conditions
if(empty($this->settings[$Model->alias]['conditions'])) {
$childrenCount = ($node[$Model->alias][$this->settings[$Model->alias]['right']] - $node[$Model->alias][$this->settings[$Model->alias]['left']] - 1) / 2;
} else {
$childrenCount = $Model->find('count', array(
'conditions' => array(
array_merge(array(), array(
$Model->alias . '.' . $this->settings[$Model->alias]['left'] . ' >' => $node[$Model->alias][$this->settings[$Model->alias]['left']],
$Model->alias . '.' . $this->settings[$Model->alias]['right'] . ' <' => $node[$Model->alias][$this->settings[$Model->alias]['right']],
$this->settings[$Model->alias]['scope']
))
),
'contain' => false
));
}

$counts[$this->settings[$Model->alias]['counterCache']] = $childrenCount;
$counts[$this->settings[$Model->alias]['counterCache']] = $Model->find('count', array(
'conditions' => array(
array_merge(array(), array(
$Model->alias . '.' . $this->settings[$Model->alias]['left'] . ' >' => $node[$Model->alias][$this->settings[$Model->alias]['left']],
$Model->alias . '.' . $this->settings[$Model->alias]['right'] . ' <' => $node[$Model->alias][$this->settings[$Model->alias]['right']],
$this->settings[$Model->alias]['scope']
))
),
'contain' => false
));
}

//Calculate direct children count
if($this->settings[$Model->alias]['directCounterCache']) {
$directChildrenCount = $Model->find('count', array(
$counts[$this->settings[$Model->alias]['directCounterCache']] = $Model->find('count', array(
'conditions' => array(
array_merge(array(), array(
$Model->alias . '.' . $this->settings[$Model->alias]['parent'] => $id,
Expand All @@ -589,11 +581,17 @@ public function updateTreeCounterCache($Model, $id=null) {
),
'contain' => false
));

$counts[$this->settings[$Model->alias]['directCounterCache']] = $directChildrenCount;
}

$Model->id = $id;
$result = $Model->save(array($Model->alias => $counts), array('fieldList' => array_keys($counts), 'validate' => false, 'callbacks' => false));
$result = $Model->save(
array($Model->alias => $counts),
array(
'fieldList' => array_keys($counts),
'validate' => false,
'callbacks' => false
)
);

if(!empty($node[$Model->alias][$this->settings[$Model->alias]['parent']])) {
$this->updateTreeCounterCache($Model, $node[$Model->alias][$this->settings[$Model->alias]['parent']]);
Expand All @@ -617,7 +615,7 @@ public function updateTreeCounterCache($Model, $id=null) {
*
* @return Array model data
*/
private function __getNodeInfo($Model, $id) {
private function __getNodeInfo(Model $Model, $id) {
$node = $Model->find('first', array(
'conditions' => array(
$Model->alias . '.' . $Model->primaryKey => $id
Expand All @@ -642,7 +640,7 @@ private function __getNodeInfo($Model, $id) {
*
* @return Array model data
*/
public function counterCacheEnabled($Model) {
public function counterCacheEnabled(Model $Model) {
return $this->settings[$Model->alias]['counterCache'] || $this->settings[$Model->alias]['directCounterCache'];
}

Expand All @@ -656,7 +654,7 @@ public function counterCacheEnabled($Model) {
* @return mixed true if succesfully saved or false on error
* @access private
*/
private function __doTreeSave($Model, $data, $options = array()) {
private function __doTreeSave(Model $Model, $data, $options = array()) {
$return = false;

//Special case in the first run
Expand Down Expand Up @@ -694,7 +692,7 @@ private function __doTreeSave($Model, $data, $options = array()) {
* @return string The id value that the original tree behavior expects as the id parameter
* @access private
*/
private function __setScopeFromId($Model, $id) {
private function __setScopeFromId(Model $Model, $id) {
if($this->scoped($Model)) {
$scope = false;

Expand Down Expand Up @@ -736,7 +734,7 @@ private function __setScopeFromId($Model, $id) {
* @return bool True on success false if the scope couldnt be found.
* @access private
*/
private function __setScope($Model, $data = null, $beforeSave = false) {
private function __setScope(Model $Model, $data = null, $beforeSave = false) {
$scope = null;

//Is the scope given as an id?
Expand Down Expand Up @@ -777,7 +775,7 @@ private function __setScope($Model, $data = null, $beforeSave = false) {
* @return mixed The scope value.
* @access private
*/
private function __getScopeFromId($Model, $id) {
private function __getScopeFromId(Model $Model, $id) {
$data = $Model->find('first', array(
'fields' => $this->settings[$Model->alias]['scopeField'],
'conditions' => array(
Expand Down

0 comments on commit eec25c0

Please sign in to comment.