/**
  * @return void
  */
 public function generateAction()
 {
     $this->output('Checking your Phalcon version');
     if (!($sourceVersion = $this->_getSource('php_phalcon.h'))) {
         die('Sources in the specified path is not found');
     }
     $sourceVersion = ApiGenerator::getSourceVersion($sourceVersion);
     if ($this->_currentVersion != $sourceVersion) {
         die("Your current Phalcon version is '{$this->_currentVersion}', but in the sources is '{$sourceVersion}'. Task stopped");
     }
     $this->output("Ok. Your current Phalcon version is '{$this->_currentVersion}'");
     $exists = (bool) $this->db->tableExists((new Models\Versions())->getSource(), 'api');
     if (!$exists) {
         $this->output('DB schema doesn\'t exist. Creating.');
         $this->_createSchema();
     }
     $tmpVers = 'tmp-' . substr(md5(microtime()), 0, 6);
     $version = new Models\Versions();
     $version->version = $tmpVers;
     $version->changelog = $this->_getSource('../CHANGELOG');
     if (!$version->save()) {
         die(join("\n", $version->getMessages()));
     }
     $this->output('Generating API from sources');
     try {
         $list = (new \ReflectionExtension('phalcon'))->getClassNames();
         array_walk($list, [$this, '_generateClass'], $tmpVers);
     } catch (\Exception $e) {
         if ($this->db->isUnderTransaction()) {
             $this->db->rollback();
         }
         $version->delete();
         echo $e->getMessage(), PHP_EOL;
         echo $e->getFile(), ':', $e->getLine(), PHP_EOL;
         echo $e->getTraceAsString();
         die;
     }
     if (($oldVersion = Models\Versions::findFirst(['conditions' => 'version = ?0', 'bind' => [$sourceVersion]])) && !$oldVersion->delete()) {
         $version->delete();
         die($oldVersion->getMessages());
     }
     if (!$this->db->update($version->getSource(), ['version'], [$sourceVersion], "version='{$tmpVers}'")) {
         $version->delete();
         die('Unsuccessful attempt');
     }
     die('Done');
 }
 protected function _hasVersion($version = null)
 {
     $version = $version ?: $this->dispatcher->getParam('version');
     return (bool) Models\Versions::count(array('conditions' => 'version = ?0', 'bind' => array($version)));
 }