Example #1
0
 /**
  * @param $name
  * @param $actualTableName
  * @param null $module
  * @throws Zend_Tool_Framework_Client_Exception
  * @throws Zend_Tool_Project_Provider_Exception
  * @internal param bool|false $forceOverwrite
  */
 public function createDbTable($name, $actualTableName, $module = null)
 {
     $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
     // Check that there is not a dash or underscore, return if doesnt match regex
     if (preg_match('#[_-]#', $name)) {
         //throw new Zend_Tool_Project_Provider_Exception('DbTable names should be camel cased.');
         $name = $this->_normaliseName($name);
     }
     $originalName = $name;
     $name = ucfirst($name);
     // get request/response object
     $request = $this->_registry->getRequest();
     $response = $this->_registry->getResponse();
     if ($actualTableName == '') {
         throw new Zend_Tool_Project_Provider_Exception('You must provide both the DbTable name as well as the actual db table\'s name.');
     }
     if (Zend_Tool_Project_Provider_DbTable::hasResource($this->_loadedProfile, $name, $module)) {
         //throw new Zend_Tool_Project_Provider_Exception('This project already has a DbTable named ' . $name);
         $request->setPretend(true);
     }
     // alert the user about inline converted names
     $tense = $request->isPretend() ? 'would be' : 'is';
     if ($name !== $originalName) {
         $response->appendContent('Note: The canonical model name that ' . $tense . ' used with other providers is "' . $name . '";' . ' not "' . $originalName . '" as supplied', array('color' => array('yellow')));
     }
     try {
         $tableResource = Zend_Tool_Project_Provider_DbTable::createResource($this->_loadedProfile, $name, $actualTableName, $module);
     } catch (Exception $e) {
         $response = $this->_registry->getResponse();
         $response->setException($e);
         return;
     }
     // do the creation
     if ($request->isPretend()) {
         $response->appendContent('This project already has a Mapper model: ' . $tableResource->getContext()->getPath());
         $nameResponse = $this->_registry->getClient()->promptInteractiveInput("Overwrite?(y) Backup old file?(b) Cancel.(n)");
         $name = $nameResponse->getContent();
         if ($name == 'y' || $name == 'b') {
             if ($name == 'b' && file_exists($tableResource->getContext()->getPath())) {
                 $response->appendContent('Backup a model at ' . $tableResource->getContext()->getPath() . '.bak');
                 rename($tableResource->getContext()->getPath(), $tableResource->getContext()->getPath() . '.bak');
             }
             $response->appendContent('Updated create a DbTable at ' . $tableResource->getContext()->getPath());
             $tableResource->create();
         }
     } else {
         $response->appendContent('Creating a DbTable at ' . $tableResource->getContext()->getPath());
         $tableResource->create();
         $this->_storeProfile();
     }
 }