Browse Source

Removing persist object feature, it was problematic an incomplete

Jose Lorenzo Rodriguez 14 years ago
parent
commit
a02db65fd1
2 changed files with 0 additions and 310 deletions
  1. 0 92
      lib/Cake/Core/Object.php
  2. 0 218
      lib/Cake/Test/Case/Core/ObjectTest.php

+ 0 - 92
lib/Cake/Core/Object.php

@@ -166,37 +166,6 @@ class Object {
 	}
 
 /**
- * Checks for a persistent class file, if found file is opened and true returned
- * If file is not found a file is created and false returned
- * If used in other locations of the model you should choose a unique name for the persistent file
- * There are many uses for this method, see manual for examples
- *
- * @param string $name name of the class to persist
- * @param string $object the object to persist
- * @return boolean Success
- * @access protected
- * @todo add examples to manual
- */
-	protected function _persist($name, $return = null, &$object, $type = null) {
-		$file = CACHE . 'persistent' . DS . strtolower($name) . '.php';
-		if ($return === null) {
-			if (!file_exists($file)) {
-				return false;
-			} else {
-				return true;
-			}
-		}
-
-		if (!file_exists($file)) {
-			$this->_savePersistent($name, $object);
-			return false;
-		} else {
-			$this->__openPersistent($name, $type);
-			return true;
-		}
-	}
-
-/**
  * Merges this objects $property with the property in $class' definition.
  * This classes value for the property will be merged on top of $class'
  *
@@ -225,65 +194,4 @@ class Object {
 			}
 		}
 	}
-
-/**
- * You should choose a unique name for the persistent file
- *
- * There are many uses for this method, see manual for examples
- *
- * @param string $name name used for object to cache
- * @param object $object the object to persist
- * @return boolean true on save, throws error if file can not be created
- */
-	protected function _savePersistent($name, &$object) {
-		$file = 'persistent' . DS . strtolower($name) . '.php';
-		$objectArray = array(&$object);
-		$data = str_replace('\\', '\\\\', serialize($objectArray));
-		$data = '<?php $' . $name . ' = \'' . str_replace('\'', '\\\'', $data) . '\' ?>';
-		$duration = '+999 days';
-		if (Configure::read('debug') >= 1) {
-			$duration = '+10 seconds';
-		}
-		cache($file, $data, $duration);
-	}
-
-/**
- * Open the persistent class file for reading
- * Used by Object::_persist()
- *
- * @param string $name Name of persisted class
- * @param string $type Type of persistance (e.g: registry)
- * @return void
- * @access private
- */
-	private function __openPersistent($name, $type = null) {
-		$file = CACHE . 'persistent' . DS . strtolower($name) . '.php';
-		include($file);
-
-		switch ($type) {
-			case 'registry':
-				$vars = unserialize(${$name});
-				foreach ($vars['0'] as $key => $value) {
-					if (strpos($key, '_behavior') !== false) {
-						App::import('Behavior', Inflector::classify(substr($key, 0, -9)));
-					} else {
-						App::import('Model', Inflector::camelize($key));
-					}
-					unset ($value);
-				}
-				unset($vars);
-				$vars = unserialize(${$name});
-				foreach ($vars['0'] as $key => $value) {
-					ClassRegistry::addObject($key, $value);
-					unset ($value);
-				}
-				unset($vars);
-			break;
-			default:
-				$vars = unserialize(${$name});
-				$this->{$name} = $vars['0'];
-				unset($vars);
-			break;
-		}
-	}
 }

+ 0 - 218
lib/Cake/Test/Case/Core/ObjectTest.php

@@ -132,38 +132,6 @@ class RequestActionController extends Controller {
 	}
 }
 
-/**
- * RequestActionPersistentController class
- *
- * @package       cake.tests.cases.libs
- */
-class RequestActionPersistentController extends Controller {
-
-/**
-* uses property
-*
-* @var array
-* @access public
-*/
-	public $uses = array('PersisterOne');
-
-/**
-* persistModel property
-*
-* @var array
-* @access public
-*/
-	public $persistModel = true;
-
-/**
- * post pass, testing post passing
- *
- * @return array
- */
-	public function index() {
-		return 'This is a test';
-	}
-}
 
 /**
  * TestObject class
@@ -298,14 +266,6 @@ class TestObject extends Object {
 	}
 
 /**
- * testPersist
- *
- * @return void
- */
-	public function testPersist($name, $return = null, &$object, $type = null) {
-		return $this->_persist($name, $return, $object, $type);
-	}
-/**
  * undocumented function
  *
  * @return void
@@ -414,184 +374,6 @@ class ObjectTest extends CakeTestCase {
 	}
 
 /**
- * testPersist method
- *
- * @access public
- * @return void
- */
-	public function testPersist() {
-		$this->markTestIncomplete('Object::persist() is totally broken right now.');
-
-		ClassRegistry::flush();
-
-		$cacheDisable = Configure::read('Cache.disable');
-		Configure::write('Cache.disable', false);
-		@unlink(CACHE . 'persistent' . DS . 'testmodel.php');
-		$test = new stdClass;
-		$this->assertFalse($this->object->testPersist('TestModel', null, $test));
-		$this->assertFalse($this->object->testPersist('TestModel', true, $test));
-		$this->assertTrue($this->object->testPersist('TestModel', null, $test));
-		$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'testmodel.php'));
-		$this->assertTrue($this->object->testPersist('TestModel', true, $test));
-		$this->assertEqual($this->object->TestModel, $test);
-
-		@unlink(CACHE . 'persistent' . DS . 'testmodel.php');
-
-		$model = new ObjectTestModel();
-		$expected = ClassRegistry::keys();
-
-		ClassRegistry::flush();
-		$data = array('object_test_model' => $model);
-		$this->assertFalse($this->object->testPersist('ObjectTestModel', true, $data));
-		$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'objecttestmodel.php'));
-
-		$this->object->testPersist('ObjectTestModel', true, $model, 'registry');
-
-		$result = ClassRegistry::keys();
-		$this->assertEqual($expected, $result);
-
-		$newModel = ClassRegistry::getObject('object_test_model');
-		$this->assertEqual('ObjectTestModel', $newModel->name);
-
-		@unlink(CACHE . 'persistent' . DS . 'objecttestmodel.php');
-
-		Configure::write('Cache.disable', $cacheDisable);
-	}
-
-/**
- * testPersistWithRequestAction method
- *
- * @access public
- * @return void
- */
-	public function testPersistWithBehavior() {
-		$this->markTestIncomplete('Object::persist() is totally broken right now.');
-		ClassRegistry::flush();
-
-		$cacheDisable = Configure::read('Cache.disable');
-		Configure::write('Cache.disable', false);
-
-		App::build(array(
-			'models' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS),
-			'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin'. DS),
-			'behaviors' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model'. DS . 'Behavior' . DS),
-		), true);
-
-		$this->assertFalse(class_exists('PersisterOneBehaviorBehavior'));
-		$this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
-		$this->assertFalse(class_exists('TestPluginPersisterBehavior'));
-		$this->assertFalse(class_exists('TestPluginAuthors'));
-
-		$Controller = new RequestActionPersistentController();
-		$Controller->persistModel = true;
-		$Controller->constructClasses();
-
-		$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisterone.php'));
-		$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
-
-		$contents = file_get_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
-		$contents = str_replace('"PersisterOne"', '"PersisterTwo"', $contents);
-		$contents = str_replace('persister_one', 'persister_two', $contents);
-		$contents = str_replace('test_plugin_comment', 'test_plugin_authors', $contents);
-		$result = file_put_contents(CACHE . 'persistent' . DS . 'persisteroneregistry.php', $contents);
-
-		$this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
-		$this->assertTrue(class_exists('TestPluginPersisterOneBehavior'));
-		$this->assertTrue(class_exists('TestPluginComment'));
-		$this->assertFalse(class_exists('PersisterTwoBehaviorBehavior'));
-		$this->assertFalse(class_exists('TestPluginPersisterTwoBehavior'));
-		$this->assertFalse(class_exists('TestPluginAuthors'));
-
-		$Controller = new RequestActionPersistentController();
-		$Controller->persistModel = true;
-		$Controller->constructClasses();
-
-		$this->assertTrue(class_exists('PersisterOneBehaviorBehavior'));
-		$this->assertTrue(class_exists('PersisterTwoBehaviorBehavior'));
-		$this->assertTrue(class_exists('TestPluginPersisterTwoBehavior'));
-		$this->assertTrue(class_exists('TestPluginAuthors'));
-
-		@unlink(CACHE . 'persistent' . DS . 'persisterone.php');
-		@unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
-	}
-
-/**
- * testPersistWithBehaviorAndRequestAction method
- *
- * @see testPersistWithBehavior
- * @access public
- * @return void
- */
-	public function testPersistWithBehaviorAndRequestAction() {
-		$this->markTestIncomplete('Object::persist() is totally broken right now.');
-
-		ClassRegistry::flush();
-
-		$cacheDisable = Configure::read('Cache.disable');
-		Configure::write('Cache.disable', false);
-
-		$this->assertFalse(class_exists('ContainableBehavior'));
-
-		App::build(array(
-			'models' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS),
-			'behaviors' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Model'. DS . 'Behavior' . DS),
-		), true);
-
-		$this->assertFalse(class_exists('PersistOneBehaviorBehavior'));
-		$this->assertFalse(class_exists('PersistTwoBehaviorBehavior'));
-
-		$Controller = new RequestActionPersistentController();
-		$Controller->persistModel = true;
-		$Controller->constructClasses();
-
-		$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisterone.php'));
-		$this->assertTrue(file_exists(CACHE . 'persistent' . DS . 'persisteroneregistry.php'));
-
-		$keys = ClassRegistry::keys();
-		$this->assertEqual($keys, array(
-			'persister_one',
-			'comment',
-			'test_plugin_comment',
-			'test_plugin.test_plugin_comment',
-			'persister_one_behavior_behavior',
-			'test_plugin_persister_one_behavior',
-			'test_plugin.test_plugin_persister_one_behavior'
-		));
-
-		ob_start();
-		$Controller->set('content_for_layout', 'cool');
-		$Controller->render('index', 'ajax', '/layouts/ajax');
-		$result = ob_get_clean();
-
-		$keys = ClassRegistry::keys();
-		$this->assertEqual($keys, array(
-			'persister_one',
-			'comment',
-			'test_plugin_comment',
-			'test_plugin.test_plugin_comment',
-			'persister_one_behavior_behavior',
-			'test_plugin_persister_one_behavior',
-			'test_plugin.test_plugin_persister_one_behavior',
-			'view'
-		));
-		$result = $this->object->requestAction('/request_action_persistent/index');
-		$expected = 'This is a test';
-		$this->assertEqual($expected, $result);
-
-		@unlink(CACHE . 'persistent' . DS . 'persisterone.php');
-		@unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
-
-		$Controller = new RequestActionPersistentController();
-		$Controller->persistModel = true;
-		$Controller->constructClasses();
-
-		@unlink(CACHE . 'persistent' . DS . 'persisterone.php');
-		@unlink(CACHE . 'persistent' . DS . 'persisteroneregistry.php');
-
-		Configure::write('Cache.disable', $cacheDisable);
-	}
-
-/**
  * testToString method
  *
  * @access public