@@ -49,7 +49,7 @@ |
||
49 | 49 | * xxx is the property name). |
50 | 50 | * |
51 | 51 | * @author Wei Zhuo <weizho[at]gmail[dot]com> |
52 | - * @package Prado\Data\ActiveRecord\Scaffold |
|
52 | + * @package Prado\Data\ActiveRecord\Scaffold |
|
53 | 53 | * @since 3.1 |
54 | 54 | */ |
55 | 55 | class TScaffoldEditView extends TScaffoldBase |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @link https://github.com/pradosoft/prado |
7 | 7 | * @copyright Copyright © 2005-2016 The PRADO Group |
8 | 8 | * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
9 | - * @package Prado\Data\ActiveRecord\Scaffold |
|
9 | + * @package Prado\Data\ActiveRecord\Scaffold |
|
10 | 10 | */ |
11 | 11 | |
12 | 12 | namespace Prado\Data\ActiveRecord\Scaffold; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * file explicitly. |
33 | 33 | * |
34 | 34 | * @author Wei Zhuo <weizho[at]gmail[dot]com> |
35 | - * @package Prado\Data\ActiveRecord\Scaffold |
|
35 | + * @package Prado\Data\ActiveRecord\Scaffold |
|
36 | 36 | * @since 3.1 |
37 | 37 | */ |
38 | 38 | abstract class TScaffoldBase extends TTemplateControl |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @link https://github.com/pradosoft/prado |
7 | 7 | * @copyright Copyright © 2005-2016 The PRADO Group |
8 | 8 | * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
9 | - * @package Prado\Data\ActiveRecord\Scaffold |
|
9 | + * @package Prado\Data\ActiveRecord\Scaffold |
|
10 | 10 | */ |
11 | 11 | |
12 | 12 | namespace Prado\Data\ActiveRecord\Scaffold; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * file explicitly. |
33 | 33 | * |
34 | 34 | * @author Wei Zhuo <weizho[at]gmail[dot]com> |
35 | - * @package Prado\Data\ActiveRecord\Scaffold |
|
35 | + * @package Prado\Data\ActiveRecord\Scaffold |
|
36 | 36 | * @since 3.1 |
37 | 37 | */ |
38 | 38 | abstract class TScaffoldBase extends TTemplateControl |
@@ -111,30 +111,30 @@ discard block |
||
111 | 111 | /** |
112 | 112 | * @var boolean controls the use of a persistent connection. Default to true. |
113 | 113 | */ |
114 | - private $_persistence = true; |
|
115 | - /** |
|
116 | - * @var integer number of buckets to create for this server which in turn control its |
|
117 | - * probability of it being selected. The probability is relative to the total weight |
|
118 | - * of all servers. |
|
119 | - */ |
|
120 | - private $_weight = 1; |
|
114 | + private $_persistence = true; |
|
115 | + /** |
|
116 | + * @var integer number of buckets to create for this server which in turn control its |
|
117 | + * probability of it being selected. The probability is relative to the total weight |
|
118 | + * of all servers. |
|
119 | + */ |
|
120 | + private $_weight = 1; |
|
121 | 121 | |
122 | - private $_timeout = 360; |
|
122 | + private $_timeout = 360; |
|
123 | 123 | |
124 | - private $_retryInterval = 15; |
|
124 | + private $_retryInterval = 15; |
|
125 | 125 | /** |
126 | - * @var integer Controls the minimum value length before attempting to compress automatically. |
|
127 | - */ |
|
128 | - private $_threshold=0; |
|
126 | + * @var integer Controls the minimum value length before attempting to compress automatically. |
|
127 | + */ |
|
128 | + private $_threshold=0; |
|
129 | 129 | |
130 | 130 | /** |
131 | - * @var float Specifies the minimum amount of savings to actually store the value compressed. The supplied value must be between 0 and 1. Default value is 0.2 giving a minimum 20% compression savings. |
|
132 | - */ |
|
133 | - private $_minSavings=0.0; |
|
131 | + * @var float Specifies the minimum amount of savings to actually store the value compressed. The supplied value must be between 0 and 1. Default value is 0.2 giving a minimum 20% compression savings. |
|
132 | + */ |
|
133 | + private $_minSavings=0.0; |
|
134 | 134 | |
135 | - private $_status = true; |
|
135 | + private $_status = true; |
|
136 | 136 | |
137 | - private $_failureCallback = null; |
|
137 | + private $_failureCallback = null; |
|
138 | 138 | |
139 | 139 | /** |
140 | 140 | * @var boolean whether to use memcached or memcache as the underlying caching extension. |
@@ -178,63 +178,63 @@ discard block |
||
178 | 178 | $this->_cache = $this->_useMemcached ? new Memcached : new Memcache; |
179 | 179 | $this->loadConfig($config); |
180 | 180 | if(count($this->_servers)) |
181 | - { |
|
182 | - foreach($this->_servers as $server) |
|
183 | - { |
|
184 | - Prado::trace('Adding server '.$server['Host'].' from serverlist', '\Prado\Caching\TMemCache'); |
|
185 | - if($this->_cache->addServer($server['Host'],$server['Port'],$server['Persistent'], |
|
186 | - $server['Weight'],$server['Timeout'],$server['RetryInterval'])===false) |
|
187 | - throw new TConfigurationException('memcache_connection_failed',$server['Host'],$server['Port']); |
|
188 | - } |
|
189 | - } |
|
190 | - else |
|
191 | - { |
|
192 | - Prado::trace('Adding server '.$this->_host, '\Prado\Caching\TMemCache'); |
|
193 | - if($this->_cache->addServer($this->_host,$this->_port)===false) |
|
194 | - throw new TConfigurationException('memcache_connection_failed',$this->_host,$this->_port); |
|
195 | - } |
|
181 | + { |
|
182 | + foreach($this->_servers as $server) |
|
183 | + { |
|
184 | + Prado::trace('Adding server '.$server['Host'].' from serverlist', '\Prado\Caching\TMemCache'); |
|
185 | + if($this->_cache->addServer($server['Host'],$server['Port'],$server['Persistent'], |
|
186 | + $server['Weight'],$server['Timeout'],$server['RetryInterval'])===false) |
|
187 | + throw new TConfigurationException('memcache_connection_failed',$server['Host'],$server['Port']); |
|
188 | + } |
|
189 | + } |
|
190 | + else |
|
191 | + { |
|
192 | + Prado::trace('Adding server '.$this->_host, '\Prado\Caching\TMemCache'); |
|
193 | + if($this->_cache->addServer($this->_host,$this->_port)===false) |
|
194 | + throw new TConfigurationException('memcache_connection_failed',$this->_host,$this->_port); |
|
195 | + } |
|
196 | 196 | if($this->_threshold!==0) |
197 | - $this->_cache->setCompressThreshold($this->_threshold,$this->_minSavings); |
|
197 | + $this->_cache->setCompressThreshold($this->_threshold,$this->_minSavings); |
|
198 | 198 | $this->_initialized=true; |
199 | 199 | parent::init($config); |
200 | 200 | } |
201 | 201 | |
202 | - /** |
|
202 | + /** |
|
203 | 203 | * Loads configuration from an XML element |
204 | 204 | * @param TXmlElement configuration node |
205 | 205 | * @throws TConfigurationException if log route class or type is not specified |
206 | 206 | */ |
207 | 207 | private function loadConfig($xml) |
208 | 208 | { |
209 | - if($xml instanceof TXmlElement) |
|
209 | + if($xml instanceof TXmlElement) |
|
210 | 210 | { |
211 | - foreach($xml->getElementsByTagName('server') as $serverConfig) |
|
212 | - { |
|
213 | - $properties=$serverConfig->getAttributes(); |
|
214 | - if(($host=$properties->remove('Host'))===null) |
|
215 | - throw new TConfigurationException('memcache_serverhost_required'); |
|
216 | - if(($port=$properties->remove('Port'))===null) |
|
217 | - throw new TConfigurationException('memcache_serverport_required'); |
|
218 | - if(!is_numeric($port)) |
|
219 | - throw new TConfigurationException('memcache_serverport_invalid'); |
|
220 | - $server = array('Host'=>$host,'Port'=>$port,'Weight'=>1,'Timeout'=>1800,'RetryInterval'=>15,'Persistent'=>true); |
|
221 | - $checks = array( |
|
222 | - 'Weight'=>'memcache_serverweight_invalid', |
|
223 | - 'Timeout'=>'memcache_servertimeout_invalid', |
|
224 | - 'RetryInterval'=>'memcach_serverretryinterval_invalid' |
|
225 | - ); |
|
226 | - foreach($checks as $property=>$exception) |
|
227 | - { |
|
228 | - $value=$properties->remove($property); |
|
229 | - if($value!==null && is_numeric($value)) |
|
230 | - $server[$property]=$value; |
|
231 | - else if($value!==null) |
|
232 | - throw new TConfigurationException($exception); |
|
233 | - } |
|
234 | - $server['Persistent']= TPropertyValue::ensureBoolean($properties->remove('Persistent')); |
|
235 | - $this->_servers[]=$server; |
|
236 | - } |
|
237 | - } |
|
211 | + foreach($xml->getElementsByTagName('server') as $serverConfig) |
|
212 | + { |
|
213 | + $properties=$serverConfig->getAttributes(); |
|
214 | + if(($host=$properties->remove('Host'))===null) |
|
215 | + throw new TConfigurationException('memcache_serverhost_required'); |
|
216 | + if(($port=$properties->remove('Port'))===null) |
|
217 | + throw new TConfigurationException('memcache_serverport_required'); |
|
218 | + if(!is_numeric($port)) |
|
219 | + throw new TConfigurationException('memcache_serverport_invalid'); |
|
220 | + $server = array('Host'=>$host,'Port'=>$port,'Weight'=>1,'Timeout'=>1800,'RetryInterval'=>15,'Persistent'=>true); |
|
221 | + $checks = array( |
|
222 | + 'Weight'=>'memcache_serverweight_invalid', |
|
223 | + 'Timeout'=>'memcache_servertimeout_invalid', |
|
224 | + 'RetryInterval'=>'memcach_serverretryinterval_invalid' |
|
225 | + ); |
|
226 | + foreach($checks as $property=>$exception) |
|
227 | + { |
|
228 | + $value=$properties->remove($property); |
|
229 | + if($value!==null && is_numeric($value)) |
|
230 | + $server[$property]=$value; |
|
231 | + else if($value!==null) |
|
232 | + throw new TConfigurationException($exception); |
|
233 | + } |
|
234 | + $server['Persistent']= TPropertyValue::ensureBoolean($properties->remove('Persistent')); |
|
235 | + $this->_servers[]=$server; |
|
236 | + } |
|
237 | + } |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -178,12 +178,12 @@ discard block |
||
178 | 178 | public function validate() |
179 | 179 | { |
180 | 180 | if (! |
181 | - ( |
|
181 | + ( |
|
182 | 182 | ($challenge = @$_POST[$this->getChallengeFieldName()]) |
183 | 183 | and |
184 | 184 | ($response = @$_POST[$this->getResponseFieldName()]) |
185 | - ) |
|
186 | - ) |
|
185 | + ) |
|
186 | + ) |
|
187 | 187 | return false; |
188 | 188 | |
189 | 189 | return $this->recaptcha_check_answer( |
@@ -350,14 +350,14 @@ discard block |
||
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
353 | - * Calls an HTTP POST function to verify if the user's guess was correct |
|
354 | - * @param string $privkey |
|
355 | - * @param string $remoteip |
|
356 | - * @param string $challenge |
|
357 | - * @param string $response |
|
358 | - * @param array $extra_params an array of extra variables to post to the server |
|
359 | - * @return bool |
|
360 | - */ |
|
353 | + * Calls an HTTP POST function to verify if the user's guess was correct |
|
354 | + * @param string $privkey |
|
355 | + * @param string $remoteip |
|
356 | + * @param string $challenge |
|
357 | + * @param string $response |
|
358 | + * @param array $extra_params an array of extra variables to post to the server |
|
359 | + * @return bool |
|
360 | + */ |
|
361 | 361 | private function recaptcha_check_answer($privkey, $remoteip, $challenge, $response, $extra_params = array()) |
362 | 362 | { |
363 | 363 | //discard spam submissions |
@@ -26,13 +26,13 @@ |
||
26 | 26 | if(!defined('PRADO_DIR')) |
27 | 27 | define('PRADO_DIR', __DIR__); |
28 | 28 | /** |
29 | - * Defines the default permission for writable directories and files |
|
30 | - */ |
|
29 | + * Defines the default permission for writable directories and files |
|
30 | + */ |
|
31 | 31 | if(!defined('PRADO_CHMOD')) |
32 | 32 | define('PRADO_CHMOD',0777); |
33 | 33 | /** |
34 | - * Defines the Composer's vendor/ path. |
|
35 | - */ |
|
34 | + * Defines the Composer's vendor/ path. |
|
35 | + */ |
|
36 | 36 | if(!defined('PRADO_VENDORDIR')) |
37 | 37 | { |
38 | 38 | $reflector = new \ReflectionClass('\Composer\Autoload\ClassLoader'); |
@@ -623,31 +623,31 @@ discard block |
||
623 | 623 | */ |
624 | 624 | class PradoCommandLineActiveRecordGenAll extends PradoCommandLineAction |
625 | 625 | { |
626 | - protected $action = 'generateAll'; |
|
627 | - protected $parameters = array('output'); |
|
628 | - protected $optional = array('directory', 'soap', 'overwrite', 'prefix', 'postfix'); |
|
629 | - protected $description = "Generate Active Record skeleton for all Tables to <output> file using application.xml in [directory]. May also generate [soap] properties.\nGenerated Classes are named like the Table with optional [Prefix] and/or [Postfix]. [Overwrite] is used to overwrite existing Files."; |
|
630 | - private $_soap = false; |
|
631 | - private $_prefix = ''; |
|
632 | - private $_postfix = ''; |
|
633 | - private $_overwrite = false; |
|
634 | - |
|
635 | - public function performAction($args) { |
|
636 | - $app_dir = count($args) > 2 ? $this->getAppDir($args[2]) : $this->getAppDir(); |
|
637 | - $this->_soap = count($args) > 3 ? ($args[3] == "soap" || $args[3] == "true" ? true : false) : false; |
|
638 | - $this->_overwrite = count($args) > 4 ? ($args[4] == "overwrite" || $args[4] == "true" ? true : false) : false; |
|
639 | - $this->_prefix = count($args) > 5 ? $args[5] : ''; |
|
640 | - $this->_postfix = count($args) > 6 ? $args[6] : ''; |
|
641 | - |
|
642 | - if ($app_dir !== false) { |
|
643 | - $config = $this->getActiveRecordConfig($app_dir); |
|
644 | - |
|
645 | - $manager = TActiveRecordManager::getInstance(); |
|
646 | - $con = $manager->getDbConnection(); |
|
647 | - $con->Active = true; |
|
648 | - |
|
649 | - switch($con->getDriverName()) |
|
650 | - { |
|
626 | + protected $action = 'generateAll'; |
|
627 | + protected $parameters = array('output'); |
|
628 | + protected $optional = array('directory', 'soap', 'overwrite', 'prefix', 'postfix'); |
|
629 | + protected $description = "Generate Active Record skeleton for all Tables to <output> file using application.xml in [directory]. May also generate [soap] properties.\nGenerated Classes are named like the Table with optional [Prefix] and/or [Postfix]. [Overwrite] is used to overwrite existing Files."; |
|
630 | + private $_soap = false; |
|
631 | + private $_prefix = ''; |
|
632 | + private $_postfix = ''; |
|
633 | + private $_overwrite = false; |
|
634 | + |
|
635 | + public function performAction($args) { |
|
636 | + $app_dir = count($args) > 2 ? $this->getAppDir($args[2]) : $this->getAppDir(); |
|
637 | + $this->_soap = count($args) > 3 ? ($args[3] == "soap" || $args[3] == "true" ? true : false) : false; |
|
638 | + $this->_overwrite = count($args) > 4 ? ($args[4] == "overwrite" || $args[4] == "true" ? true : false) : false; |
|
639 | + $this->_prefix = count($args) > 5 ? $args[5] : ''; |
|
640 | + $this->_postfix = count($args) > 6 ? $args[6] : ''; |
|
641 | + |
|
642 | + if ($app_dir !== false) { |
|
643 | + $config = $this->getActiveRecordConfig($app_dir); |
|
644 | + |
|
645 | + $manager = TActiveRecordManager::getInstance(); |
|
646 | + $con = $manager->getDbConnection(); |
|
647 | + $con->Active = true; |
|
648 | + |
|
649 | + switch($con->getDriverName()) |
|
650 | + { |
|
651 | 651 | case 'mysqli': |
652 | 652 | case 'mysql': |
653 | 653 | $command = $con->createCommand("SHOW TABLES"); |
@@ -665,27 +665,27 @@ discard block |
||
665 | 665 | default: |
666 | 666 | echo "\n Sorry, generateAll is not implemented for ".$con->getDriverName()."\n"; |
667 | 667 | |
668 | - } |
|
669 | - |
|
670 | - $dataReader = $command->query(); |
|
671 | - $dataReader->bindColumn(1, $table); |
|
672 | - $tables = array(); |
|
673 | - while ($dataReader->read() !== false) { |
|
674 | - $tables[] = $table; |
|
675 | - } |
|
676 | - $con->Active = False; |
|
677 | - foreach ($tables as $key => $table) { |
|
678 | - $output = $args[1] . "." . $this->_prefix . ucfirst($table) . $this->_postfix; |
|
679 | - if ($config !== false && $output !== false) { |
|
680 | - $this->generate("generate " . $table . " " . $output . " " . $this->_soap . " " . $this->_overwrite); |
|
681 | - } |
|
682 | - } |
|
683 | - } |
|
684 | - return true; |
|
685 | - } |
|
686 | - |
|
687 | - public function generate($l) |
|
688 | - { |
|
668 | + } |
|
669 | + |
|
670 | + $dataReader = $command->query(); |
|
671 | + $dataReader->bindColumn(1, $table); |
|
672 | + $tables = array(); |
|
673 | + while ($dataReader->read() !== false) { |
|
674 | + $tables[] = $table; |
|
675 | + } |
|
676 | + $con->Active = False; |
|
677 | + foreach ($tables as $key => $table) { |
|
678 | + $output = $args[1] . "." . $this->_prefix . ucfirst($table) . $this->_postfix; |
|
679 | + if ($config !== false && $output !== false) { |
|
680 | + $this->generate("generate " . $table . " " . $output . " " . $this->_soap . " " . $this->_overwrite); |
|
681 | + } |
|
682 | + } |
|
683 | + } |
|
684 | + return true; |
|
685 | + } |
|
686 | + |
|
687 | + public function generate($l) |
|
688 | + { |
|
689 | 689 | $input = explode(" ", trim($l)); |
690 | 690 | if(count($input) > 2) |
691 | 691 | { |
@@ -702,49 +702,49 @@ discard block |
||
702 | 702 | { |
703 | 703 | echo "\n Usage: generate table_name Application.pages.RecordClassName\n"; |
704 | 704 | } |
705 | - } |
|
706 | - |
|
707 | - protected function getAppDir($dir=".") { |
|
708 | - if (is_dir($dir)) |
|
709 | - return realpath($dir); |
|
710 | - if (false !== ($app_dir = realpath($dir . '/protected/')) && is_dir($app_dir)) |
|
711 | - return $app_dir; |
|
712 | - echo '** Unable to find directory "' . $dir . "\".\n"; |
|
713 | - return false; |
|
714 | - } |
|
715 | - |
|
716 | - protected function getXmlFile($app_dir) { |
|
717 | - if (false !== ($xml = realpath($app_dir . '/application.xml')) && is_file($xml)) |
|
718 | - return $xml; |
|
719 | - if (false !== ($xml = realpath($app_dir . '/protected/application.xml')) && is_file($xml)) |
|
720 | - return $xml; |
|
721 | - echo '** Unable to find application.xml in ' . $app_dir . "\n"; |
|
722 | - return false; |
|
723 | - } |
|
724 | - |
|
725 | - protected function getActiveRecordConfig($app_dir) { |
|
726 | - if (false === ($xml = $this->getXmlFile($app_dir))) |
|
727 | - return false; |
|
728 | - if (false !== ($app = $this->initializePradoApplication($app_dir))) { |
|
729 | - Prado::using('System.Data.ActiveRecord.TActiveRecordConfig'); |
|
730 | - foreach ($app->getModules() as $module) |
|
731 | - if ($module instanceof TActiveRecordConfig) |
|
732 | - return $module; |
|
733 | - echo '** Unable to find TActiveRecordConfig module in ' . $xml . "\n"; |
|
734 | - } |
|
735 | - return false; |
|
736 | - } |
|
737 | - |
|
738 | - protected function getOutputFile($app_dir, $namespace) { |
|
739 | - if (is_file($namespace) && strpos($namespace, $app_dir) === 0) |
|
740 | - return $namespace; |
|
741 | - $file = Prado::getPathOfNamespace($namespace, ""); |
|
742 | - if ($file !== null && false !== ($path = realpath(dirname($file))) && is_dir($path)) { |
|
743 | - if (strpos($path, $app_dir) === 0) |
|
744 | - return $file; |
|
745 | - } |
|
746 | - echo '** Output file ' . $file . ' must be within directory ' . $app_dir . "\n"; |
|
747 | - return false; |
|
748 | - } |
|
705 | + } |
|
706 | + |
|
707 | + protected function getAppDir($dir=".") { |
|
708 | + if (is_dir($dir)) |
|
709 | + return realpath($dir); |
|
710 | + if (false !== ($app_dir = realpath($dir . '/protected/')) && is_dir($app_dir)) |
|
711 | + return $app_dir; |
|
712 | + echo '** Unable to find directory "' . $dir . "\".\n"; |
|
713 | + return false; |
|
714 | + } |
|
715 | + |
|
716 | + protected function getXmlFile($app_dir) { |
|
717 | + if (false !== ($xml = realpath($app_dir . '/application.xml')) && is_file($xml)) |
|
718 | + return $xml; |
|
719 | + if (false !== ($xml = realpath($app_dir . '/protected/application.xml')) && is_file($xml)) |
|
720 | + return $xml; |
|
721 | + echo '** Unable to find application.xml in ' . $app_dir . "\n"; |
|
722 | + return false; |
|
723 | + } |
|
724 | + |
|
725 | + protected function getActiveRecordConfig($app_dir) { |
|
726 | + if (false === ($xml = $this->getXmlFile($app_dir))) |
|
727 | + return false; |
|
728 | + if (false !== ($app = $this->initializePradoApplication($app_dir))) { |
|
729 | + Prado::using('System.Data.ActiveRecord.TActiveRecordConfig'); |
|
730 | + foreach ($app->getModules() as $module) |
|
731 | + if ($module instanceof TActiveRecordConfig) |
|
732 | + return $module; |
|
733 | + echo '** Unable to find TActiveRecordConfig module in ' . $xml . "\n"; |
|
734 | + } |
|
735 | + return false; |
|
736 | + } |
|
737 | + |
|
738 | + protected function getOutputFile($app_dir, $namespace) { |
|
739 | + if (is_file($namespace) && strpos($namespace, $app_dir) === 0) |
|
740 | + return $namespace; |
|
741 | + $file = Prado::getPathOfNamespace($namespace, ""); |
|
742 | + if ($file !== null && false !== ($path = realpath(dirname($file))) && is_dir($path)) { |
|
743 | + if (strpos($path, $app_dir) === 0) |
|
744 | + return $file; |
|
745 | + } |
|
746 | + echo '** Output file ' . $file . ' must be within directory ' . $app_dir . "\n"; |
|
747 | + return false; |
|
748 | + } |
|
749 | 749 | |
750 | 750 | } |