1 <?php
2
3 /**
4 * EDbMigration
5 *
6 * @link http://www.yiiframework.com/extension/extended-database-migration/
7 * @link http://www.yiiframework.com/doc/guide/1.1/en/database.migration
8 * @author Carsten Brandt <mail@cebe.cc>
9 * @version 0.8.0-dev
10 */
11 class EDbMigration extends CDbMigration
12 {
13 /**
14 * @var EMigrateCommand
15 */
16 private $migrateCommand;
17 protected $interactive = true;
18
19 /**
20 * @param EMigrateCommand $migrateCommand
21 */
22 public function setCommand($migrateCommand)
23 {
24 $this->migrateCommand = $migrateCommand;
25 $this->interactive = $migrateCommand->interactive;
26 }
27
28 /**
29 * @see CConsoleCommand::confirm()
30 * @param string $message
31 * @return bool
32 */
33 public function confirm($message)
34 {
35 if (!$this->interactive) {
36 return true;
37 }
38 return $this->migrateCommand->confirm($message);
39 }
40
41 /**
42 * @see CConsoleCommand::prompt()
43 * @param string $message
44 * @param mixed $defaultValue will be returned when interactive is false
45 * @return string
46 */
47 public function prompt($message, $defaultValue)
48 {
49 if (!$this->interactive) {
50 return $defaultValue;
51 }
52 return $this->migrateCommand->prompt($message);
53 }
54
55 /**
56 * Executes a SQL statement. Silently. (only show sql on exception)
57 * This method executes the specified SQL statement using {@link dbConnection}.
58 * @param string $sql the SQL statement to be executed
59 * @param array $params input parameters (name=>value) for the SQL execution. See {@link CDbCommand::execute} for more details.
60 * @param boolean $verbose
61 */
62 public function execute($sql, $params=array(), $verbose=true)
63 {
64 if ($verbose) {
65 parent::execute($sql, $params);
66 } else {
67 try {
68 echo " > execute SQL ...";
69 $time=microtime(true);
70 $this->getDbConnection()->createCommand($sql)->execute($params);
71 echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
72 } catch (CException $e) {
73 echo " failed.\n\n";
74 throw $e;
75 }
76 }
77 }
78
79 }
80