30 extends Zend_Tool_Project_Provider_Abstract
31 implements Zend_Tool_Framework_Provider_Pretendable
46 public function createResource(Zend_Tool_Project_Profile $profile, $schemaName, $contents, $force =
false)
48 if (!is_string($schemaName)) {
49 throw new Zend_Tool_Project_Provider_Exception(
50 'schema name must be a string'
54 if ($this->
_findfile($profile, $schemaName) !==
false && $force ==
false) {
55 throw new Zend_Tool_Project_Provider_Exception(
56 'File named ' . $schemaName.
' already exists within the models directory.'
60 $newFile = $profile->createResourceAt(
64 'schemaName' => $schemaName,
65 'fileContents' => $contents)
80 'ZendDbSchema_Tool_Project_Context_Schema_File',
81 'ZendDbSchema_Tool_Project_Context_Schema_Directory'
95 $existingFile = $profile->search(array(
97 'file' => array(
'filesystemName' => $name))
114 throw new Zend_Tool_Project_Provider_Exception(
'Schema name must not be empty');
125 throw new Zend_Tool_Project_Provider_Exception(
126 "Type must be table or database, '{$type}' is given."
139 public function pull($type =
'table', $name =
'', $force =
false)
144 if (!$schema->isExist()) {
145 throw new Zend_Tool_Project_Provider_Exception(
146 "No {$type} with name '{$name}' found"
152 $writer =
new Zend_Config_Writer_Array();
153 $writer->setConfig(
new Zend_Config($schema->toArray()));
155 $file = $this->
createResource($profile, $name, $writer->render(), $force);
157 if ($this->_registry->getRequest()->isPretend()) {
158 $this->_registry->getResponse()->appendContent(
159 'Would create schema at ' . $file->getPath()
162 $this->_registry->getResponse()->appendContent(
163 'Creating schema at ' . $file->getPath()
166 $this->_storeProfile();
177 public function push($type =
'table', $name =
'', $force =
false)
182 if ($schema->isExist() && !$force) {
183 throw new Zend_Tool_Project_Provider_Exception(
184 "{$type} with name {$name} already exists in database. User force for overwrite"
190 if (!$file = $this->
_findfile($profile, $name)) {
191 throw new Zend_Tool_Project_Provider_Exception(
192 "Schema file '{$name}' is not found"
196 $config = include $file->getPath();
198 $schema->setFromArray($config);
200 if (!$schema->isDirty()) {
201 throw new Zend_Tool_Project_Provider_Exception(
202 "{$type} with name {$name} is not modified"
205 if ($this->_registry->getRequest()->isPretend()) {
206 $this->_registry->getResponse()->appendContent(
207 'Would exequte following sql code' .PHP_EOL . $schema->toSql(
true)
210 $this->_registry->getResponse()->appendContent(
214 $this->_storeProfile();
233 if (!$file = $this->
_findfile($profile, $name)) {
234 throw new Zend_Tool_Project_Provider_Exception(
235 "Schema file '{$name}' is not found"
239 $config = include $file->getPath();
241 $schema->setFromArray($config);
244 if ($schema->isDirty()) {
259 return $name .
'.' . $type .
'.php';
269 $profile = $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
271 $bootstrapResource = $this->_loadedProfile->search(
'BootstrapFile');
274 $zendApp = $bootstrapResource->getApplicationInstance();
277 $zendApp->bootstrap(
'db');
278 Zend_Loader_Autoloader::getInstance()->registerNamespace(
'ZendDbSchema');
279 }
catch (Zend_Application_Exception $e) {
280 throw new Zend_Tool_Project_Provider_Exception(
'Db resource not available, you might need to configure a DbAdapter.');