Skip to content

Commit

Permalink
Attempted fix for issue #1074 and issue #957 where adding language wa…
Browse files Browse the repository at this point in the history
…s causing an exception and missing column errors. This commit also contains various unrelated code documentation additions.
  • Loading branch information
ryancramerdesign committed Apr 13, 2015
1 parent 4a372a3 commit b1b46e4
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 124 deletions.
13 changes: 12 additions & 1 deletion wire/core/DatabaseQuery.php
Expand Up @@ -16,6 +16,8 @@
*
* http://www.processwire.com
* http://www.ryancramer.com
*
* @property array $where
*
*/
abstract class DatabaseQuery extends WireData {
Expand Down Expand Up @@ -56,6 +58,9 @@ public function __get($key) {

/**
* Merge the contents of current query with another
*
* @param DatabaseQuery $query
* @return this
*
*/
public function merge(DatabaseQuery $query) {
Expand All @@ -82,7 +87,13 @@ protected function getQueryWhere() {
foreach($where as $s) $sql .= "\nAND $s ";
return $sql;
}


/**
* Prepare and return a PDOStatement
*
* @return PDOStatement
*
*/
public function prepare() {
$query = $this->wire('database')->prepare($this->getQuery());
foreach($this->bindValues as $key => $value) {
Expand Down
32 changes: 29 additions & 3 deletions wire/core/Fieldtype.php
Expand Up @@ -12,6 +12,32 @@
* http://processwire.com
*
*
* Hookable methods
* ================
* @method InputfieldWrapper getConfigInputfields(Field $field)
* @method InputfieldWrapper getConfigAdvancedInputfields(Field $field)
* @method array getConfigAllowContext(Field $field)
* @method array exportConfigData(Field $field, array $data)
* @method array importConfigData(Field $field, array $data)
* @method Fieldtypes|null getCompatibleFieldtypes(Field $field)
* @method mixed formatValue(Page $page, Field $field, $value)
* @method string|MarkupFieldtype markupValue(Page $page, Field $field, $value = null, $property = '')
* @method mixed wakeupValue(Page $page, Field $field, $value)
* @method string|int|array sleepValue(Page $page, Field $field, $value)
* @method string|float|int|array exportValue(Page $page, Field $field, $value, array $options = array())
* @method bool createField(Field $field)
* @method array getSelectorInfo(Field $field, array $data = array())
* @method mixed|null loadPageField(Page $page, Field $field)
* @method bool savePageField(Page $page, Field $field)
* @method bool deleteField(Field $field)
* @method bool deletePageField(Page $page, Field $field)
* @method bool emptyPageField(Page $page, Field $field)
* @method bool replacePageField(Page $src, Page $dst, Field $field)
* @method bool deleteTemplateField(Template $template, Field $field)
* @method Field cloneField(Field $field)
* @method void install()
* @method void uninstall()
*
*/
abstract class Fieldtype extends WireData implements Module {

Expand Down Expand Up @@ -620,13 +646,13 @@ public function ___loadPageField(Page $page, Field $field) {
if($isMulti) $query->orderby('sort');

$value = null;
$stmt = $query->prepare();
try {
$stmt->execute();
$stmt = $query->prepare();
$result = $this->wire('pages')->executeQuery($stmt);
} catch(Exception $e) {
$result = false;
$this->error($e->getMessage());
}
$result = $stmt->errorCode() > 0 ? false : true;
$fieldName = $database->escapeCol($field->name);
$schema = $this->trimDatabaseSchema($this->getDatabaseSchema($field));

Expand Down
5 changes: 3 additions & 2 deletions wire/core/Inputfield.php
Expand Up @@ -63,8 +63,9 @@ interface InputfieldHasArrayValue { }
* @property string $headerClass Optional class name (CSS) to apply to the InputfieldHeader element
* @property string $contentClass Optional class name (CSS) to apply to the InputfieldContent element
* @property InputfieldWrapper|null $parent The parent InputfieldWrapper for this Inputfield or null if not set.
* @property null|Fieldtype hasFieldtype Set to the Fieldtype using this Inputfield (by Field), when applicable, null when not.
* @property null|bool entityEncodeLabel Set to boolean false to specifically disable entity encoding of field header/label.
* @property null|Fieldtype $hasFieldtype Set to the Fieldtype using this Inputfield (by Field), when applicable, null when not.
* @property null|bool $entityEncodeLabel Set to boolean false to specifically disable entity encoding of field header/label.
* @property bool|null $useLanguages When multi-language support active, can be set to true to make it provide inputs for each language (where supported).
*
*
*
Expand Down
14 changes: 14 additions & 0 deletions wire/core/Page.php
Expand Up @@ -38,7 +38,9 @@
* @property Page $prev This page's previous sibling page, or NullPage if it is the first sibling. See also $page->prev($pageArray).
* @property string $created Unix timestamp of when the page was created
* @property string $modified Unix timestamp of when the page was last modified
* @property int $created_users_id ID of created user
* @property User $createdUser The user that created this page. Returns a User or a NullUser.
* @property int $modified_users_id ID of last modified user
* @property User $modifiedUser The user that last modified this page. Returns a User or a NullUser.
* @property PagefilesManager $filesManager
* @property bool $outputFormatting Whether output formatting is enabled or not.
Expand All @@ -48,7 +50,9 @@
* @property int $sort Sort order of this page relative to siblings (applicable when manual sorting is used).
* @property string $sortfield Field that a page is sorted by relative to its siblings (default=sort, which means drag/drop manual)
* @property null|array _statusCorruptedFields Field names that caused the page to have Page::statusCorrupted status.
* @property int $status Page status flags
* @property string statusStr Returns space-separated string of status names active on this page.
* @property Fieldgroup $fieldgroup Shorter alias for $page->template->fieldgroup
*
* Methods added by PageRender.module:
* -----------------------------------
Expand All @@ -70,6 +74,14 @@
* ------------------------------------------------------------------
* @method Page setLanguageValue($language, $fieldName, $value) Set value for field in language (requires LanguageSupport module). $language may be ID, language name or Language object.
* @method Page getLanguageValue($language, $fieldName) Get value for field in language (requires LanguageSupport module). $language may be ID, language name or Language object.
*
* Hookable methods
* ----------------
* @method mixed getUnknown($key) Last stop to find a property that we haven't been able to locate.
* @method Page rootParent() Get parent closest to homepage.
* @method void loaded() Called when page is loaded.
* @method void setEditor(WirePageEditor $editor)
* @method string getIcon()
*
*/

Expand Down Expand Up @@ -1263,6 +1275,8 @@ public function prevUntil($selector = '', $filter = '', PageArray $siblings = nu
*
* @param Field|string $field Optional field to save (name of field or Field object)
* @param array $options See Pages::save for options. You may also specify $options as the first argument if no $field is needed.
* @return bool true on success false on fail
* @throws WireException on database error
*
*/
public function save($field = null, array $options = array()) {
Expand Down
33 changes: 15 additions & 18 deletions wire/core/PageFinder.php
Expand Up @@ -123,6 +123,9 @@ public function __construct() {

/**
* Pre-process the selectors to add Page status checks
*
* @param Selectors $selectors
* @param array $options
*
*/
protected function setupStatusChecks(Selectors $selectors, array &$options) {
Expand Down Expand Up @@ -248,6 +251,11 @@ protected function setupStatusChecks(Selectors $selectors, array &$options) {

/**
* Return all pages matching the given selector.
*
* @param Selectors $selectors
* @param array $options
* @return array
* @throws PageFinderException
*
*/
public function ___find(Selectors $selectors, $options = array()) {
Expand Down Expand Up @@ -278,23 +286,12 @@ public function ___find(Selectors $selectors, $options = array()) {

try {
$stmt = $query->prepare();
$stmt->execute();
$this->wire('pages')->executeQuery($stmt);
$error = '';
} catch(Exception $e) {
$error = $e->getMessage();
}

if($stmt->errorCode() > 0) {
$errorInfo = $stmt->errorInfo();
$error = $errorInfo[2] . ($error ? " - $error" : "");
if($stmt->errorCode() == '42S22') {
// unknown column
if(preg_match('/[\'"]([_a-z0-9]+\.[_a-z0-9]+)[\'"]/i', $errorInfo[2], $matches)) {
$this->unknownColumnError($matches[1], $errorInfo[2], $query);
}
}
}

if($error) {
$this->log($error);
throw new PageFinderException($error);
Expand Down Expand Up @@ -345,12 +342,6 @@ public function ___find(Selectors $selectors, $options = array()) {
return $matches;
}

protected function ___unknownColumnError($column, $error, DatabaseQuery $query) {
if($this->wire('languages')) {
$this->wire('languages')->unknownColumnError($column);
}
}

/**
* Same as find() but returns just a simple array of page IDs without any other info
*
Expand Down Expand Up @@ -1153,6 +1144,7 @@ protected function ___getQueryJoinPath(DatabaseQuerySelect $query, $selector) {
if($this->modules->isInstalled('PagePaths') && !$langNames) {
// @todo add support to PagePaths module for LanguageSupportPageNames
$pagePaths = $this->modules->get('PagePaths');
/** @var PagePaths $pagePaths */
$pagePaths->getMatchQuery($query, $selector);
return;
}
Expand Down Expand Up @@ -1203,6 +1195,11 @@ protected function ___getQueryJoinPath(DatabaseQuerySelect $query, $selector) {
* Special case when field is native to the pages table
*
* TODO not all operators will work here, so may want to add some translation or filtering
*
* @param DatabaseQuerySelect $query
* @param Selector $selector
* @param array $fields
* @throws PageFinderSyntaxException
*
*/
protected function getQueryNativeField(DatabaseQuerySelect $query, $selector, $fields) {
Expand Down

0 comments on commit b1b46e4

Please sign in to comment.