1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-22 06:13:57 +02:00

Update numerous core classes to support the new wired() method, plus correct any found instances of the ProcessWire instance not being passed along to a Wire derived instance.

This commit is contained in:
Ryan Cramer
2020-05-29 14:09:17 -04:00
parent 365af73635
commit d2e381f987
38 changed files with 193 additions and 93 deletions

View File

@@ -97,6 +97,10 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl
'dl' => 'uk-description-list uk-description-list-divider',
));
}
public function wired() {
parent::wired();
$this->addHookAfter('InputfieldSelector::ajaxReady', $this, 'hookInputfieldSelectorAjax');
}

View File

@@ -80,7 +80,7 @@ class FieldtypeComments extends FieldtypeMulti {
);
}
public function __construct() {
public function wired() {
if($this->wire('config')->ajax) {
$this->addHookBefore('Page::render', $this, 'checkVoteAction');
}
@@ -2007,7 +2007,7 @@ class FieldtypeComments extends FieldtypeMulti {
$result = false;
$this->error($e->getMessage());
}
if($result) try {
if($result !== false) try {
$database->exec("DROP TABLE `{$table}_votes`"); // QA
} catch(\Exception $e) {
// ok to ignore, as table may not exist

View File

@@ -191,7 +191,7 @@ class InputfieldCommentsAdmin extends Inputfield implements InputfieldItemList {
$this->commentIDsToNumbers[$comment->id] = ++$n;
}
$fieldset = new InputfieldWrapper();
$fieldset = new InputfieldWrapper(); // wired
$this->wire($fieldset);
$n = 0;

View File

@@ -1134,7 +1134,7 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule {
try {
$result = $database->exec("ALTER TABLE `{$table}` ADD `$column` $schema[$column]");
if($result) {
if($result !== false) {
if(isset($schema['keys'][$column])) {
$database->exec("ALTER TABLE `{$table}` ADD " . $schema['keys'][$column]);
}
@@ -1299,7 +1299,8 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule {
if($isNew) {
$sql = "INSERT INTO $table SET pages_id=:pages_id, sort=:sort, $sets";
$binds[":sort"] = $this->getMaxColumnValue($page, $field, 'sort');
$sort = $this->getMaxColumnValue($page, $field, 'sort', -1);
$binds[":sort"] = ++$sort;
} else {
$sql = "UPDATE $table SET $sets WHERE pages_id=:pages_id AND data=:name";
$binds[':name'] = $pagefile->name;

View File

@@ -37,9 +37,13 @@ class FieldtypeOptions extends FieldtypeMulti implements Module {
require_once($path . 'SelectableOption.php');
require_once($path . 'SelectableOptionArray.php');
require_once($path . 'SelectableOptionManager.php');
$this->manager = $this->wire(new SelectableOptionManager());
parent::__construct();
}
public function wired() {
$this->manager = $this->wire(new SelectableOptionManager());
parent::wired();
}
/**
* Get a property from the Fieldtype

View File

@@ -45,11 +45,12 @@ class SelectableOptionManager extends Wire {
*/
protected $removedOptionIDs = array();
public function __construct() {
public function wired() {
if($this->wire('modules')->isInstalled('LanguageSupportFields')) {
$this->useLanguages = true;
$this->useLanguages = true;
$this->addHookAfter('Languages::updated', $this, 'updateLanguages');
}
parent::wired();
}
/**

View File

@@ -344,7 +344,7 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList {
$inputfields = $this->getRepeaterItemInputfields($page);
$isLoaded = true;
} else {
$inputfields = new InputfieldWrapper(); // non loaded
$inputfields = $this->wire(new InputfieldWrapper()); // non loaded
$isLoaded = false;
}
$inputfields->set('useDependencies', false);

View File

@@ -53,12 +53,16 @@ class InputfieldCheckbox extends Inputfield {
$this->set('checkboxLabel', ''); // typically specified by interactive config
$this->set('labelAttrs', array()); // Optional attributes for <label> element that surrounds checkbox (3.0.141+)
parent::__construct();
}
public function wired() {
/** @var Languages $languages */
$languages = $this->wire('languages');
if($languages) foreach($languages as $language) {
if(!$language->isDefault()) $this->set("checkboxLabel$language", "");
if(!$language->isDefault()) $this->set("checkboxLabel$language", "");
}
parent::__construct();
parent::wired();
}
/**

View File

@@ -70,7 +70,7 @@ class InputfieldDatetimeSelect extends InputfieldDatetimeType {
public function render() {
$name = $this->getAttribute('name');
$value = $this->getAttribute('value');
$value = (int) $this->getAttribute('value');
$valueYear = $value ? date('Y', $value) : 0;
$yearLock = $this->getSetting('yearLock');
$format = $this->getSetting('dateSelectFormat');

View File

@@ -2,6 +2,8 @@
/**
* An Inputfield for handling ProcessWire "name" fields
*
* @property string $sanitizeMethod
*
*/
class InputfieldName extends InputfieldText {
@@ -33,7 +35,12 @@ class InputfieldName extends InputfieldText {
}
protected function setAttributeValue($value) {
$value = call_user_func(array($this->wire('sanitizer'), $this->sanitizeMethod), $value);
$sanitizeMethod = $this->sanitizeMethod;
if($this->isWired()) {
$value = call_user_func(array($this->wire('sanitizer'), $sanitizeMethod), $value);
} else {
$value = wire('sanitizer')->$sanitizeMethod($value);
}
return $value;
}

View File

@@ -38,8 +38,6 @@ class InputfieldText extends Inputfield {
/**
* Construct
*
* @throws WireException
*
*/
public function __construct() {
parent::__construct();
@@ -54,13 +52,17 @@ class InputfieldText extends Inputfield {
$this->set('stripTags', false); // strip tags from input?
$this->set('noTrim', false);
$this->set('showCount', self::showCountNone);
}
public function wired() {
// if multi-language, support placeholders for each language
/** @var Languages $languages */
$languages = $this->wire('languages');
if($languages) foreach($languages as $language) {
// set to blank value so that Field::getInputfield() will recogize this setting is for InputfieldText
if(!$language->isDefault()) $this->set("placeholder$language", '');
}
parent::wired();
}
/**

View File

@@ -153,6 +153,10 @@ class InputfieldToggle extends Inputfield {
$this->attr('value', self::valueUnknown);
parent::__construct();
}
public function wired() {
$languages = $this->wire('languages');
if($languages) {
foreach($languages as $language) {
@@ -162,8 +166,7 @@ class InputfieldToggle extends Inputfield {
$this->set("otherLabel$language", '');
}
}
parent::__construct();
parent::wired();
}
/**

View File

@@ -27,8 +27,7 @@ class JqueryCore extends ModuleJS {
*/
const devMode = false;
public function __construct() {
public function wired() {
$this->addComponents(array(
'core-dev' => 'jquery-1.11.1.js',
'latest' => 'jquery-1.11.1.js',
@@ -39,16 +38,18 @@ class JqueryCore extends ModuleJS {
'longclick' => 'jquery.longclick.min.js',
'simulate' => 'jquery.simulate.min.js',
'xregexp' => 'xregexp.js', // no "min.js" intended
));
));
$info = self::getModuleInfo();
$this->config->scripts->prepend($this->config->urls->JqueryCore . "JqueryCore.js?v=$info[version]");
$config = $this->config;
$config->scripts->prepend($config->urls('JqueryCore') . "JqueryCore.js?v=$info[version]");
}
public function ___use($name) {
if($name == 'latest') {
$info = self::getModuleInfo();
$this->config->scripts->remove($this->config->urls->JqueryCore . "JqueryCore.js?v=$info[version]");
$this->config->scripts->prepend($this->config->urls->JqueryCore . $this->components['latest']);
$url = $this->config->urls('JqueryCore');
$this->config->scripts->remove($url . "JqueryCore.js?v=$info[version]");
$this->config->scripts->prepend($url . $this->components['latest']);
return $this;
}
return parent::___use($name);

View File

@@ -12,13 +12,14 @@ class JqueryUI extends ModuleJS {
);
}
public function __construct() {
public function wired() {
$debug = $this->wire('config')->debug;
$this->addComponents(array(
'modal' => $debug ? 'modal.js' : 'modal.min.js',
'panel' => $debug ? 'panel.js' : 'panel.min.js',
'touch' => 'touch.js'
));
));
parent::wired();
}
public function init() {

View File

@@ -63,9 +63,13 @@ class LanguageSupportFields extends WireData implements Module {
require_once($dirname . '/LanguagesValueInterface.php');
require_once($dirname . '/FieldtypeLanguageInterface.php');
require_once($dirname . '/LanguagesPageFieldValue.php');
$this->addHookAfter('FieldtypeLanguageInterface::loadPageField', $this, 'fieldtypeLoadPageField');
$this->addHookAfter('FieldtypeLanguageInterface::wakeupValue', $this, 'fieldtypeWakeupValue');
}
public function wired() {
$this->addHookAfter('FieldtypeLanguageInterface::loadPageField', $this, 'fieldtypeLoadPageField');
$this->addHookAfter('FieldtypeLanguageInterface::wakeupValue', $this, 'fieldtypeWakeupValue');
$this->addHookAfter('FieldtypeLanguageInterface::getConfigInputfields', $this, 'fieldtypeGetConfigInputfields');
parent::wired();
}
public function init() {

View File

@@ -290,7 +290,7 @@ class LanguageSupportInstall extends Wire {
public function getModuleConfigInputfields() {
$install = $this->_('Click to install:') . ' ';
$form = new InputfieldWrapper();
$form = $this->wire(new InputfieldWrapper());
$names = array(
'LanguageSupportFields',
'LanguageSupportPageNames',

View File

@@ -314,7 +314,8 @@ class ProcessModule extends Process {
if($this->input->post('clear_file_compiler')) {
$this->session->CSRF->validate();
$compiler = new FileCompiler($this->wire('config')->paths->siteModules);
/** @var FileCompiler $compiler */
$compiler = $this->wire(new FileCompiler($this->wire('config')->paths->siteModules));
$compiler->clearCache(true);
$this->session->message($this->_('Cleared file compiler cache'));
$this->session->redirect('./');

View File

@@ -340,17 +340,17 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
*
*/
public function __construct() {
$this->set('useBookmarks', false);
$this->set('viewAction', 'this');
return parent::__construct();
}
public function wired() {
if($this->wire('process') instanceof WirePageEditor) {
// keep existing process, which may be building on top of this one
} else {
$this->wire('process', $this);
}
return parent::__construct();
}
/**
@@ -3083,6 +3083,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
public function getModuleConfigInputfields(array $data) {
$inputfields = new InputfieldWrapper();
$this->wire($inputfields);
$f = $this->wire('modules')->get('InputfieldRadios');
$f->name = 'viewAction';

View File

@@ -28,13 +28,14 @@ class ProcessPageListActions extends Wire {
'extras' => "<i class='fa fa-angle-right'></i>",
);
public function __construct() {
public function wired() {
$this->superuser = $this->wire('user')->isSuperuser();
$settings = $this->wire('config')->ProcessPageList;
$settings = $this->wire('config')->ProcessPageList;
if(is_array($settings) && isset($settings['extrasLabel'])) {
$this->actionLabels['extras'] = $settings['extrasLabel'];
}
}
parent::wired();
}
public function setActionLabels(array $actionLabels) {
$this->actionLabels = array_merge($this->actionLabels, $actionLabels);

View File

@@ -29,6 +29,10 @@ abstract class ProcessPageListRender extends Wire {
$this->children = $children;
$this->start = 0;
$this->limit = 0;
parent::__construct();
}
public function wired() {
$this->superuser = $this->wire('user')->isSuperuser();
$this->actionLabels = array(
'edit' => $this->_('Edit'), // Edit page action
@@ -49,6 +53,7 @@ abstract class ProcessPageListRender extends Wire {
$this->actions = $this->wire(new ProcessPageListActions());
$this->actions->setActionLabels($this->actionLabels);
$this->numChildrenHook = $this->wire('hooks')->isMethodHooked($this, 'getNumChildren');
parent::wired();
}
public function setOption($key, $value) {

View File

@@ -10,16 +10,15 @@ class ProcessPageListRenderJSON extends ProcessPageListRender {
protected $systemIDs = array();
public function __construct(Page $page, PageArray $children) {
parent::__construct($page, $children);
public function wired() {
$config = $this->config;
$this->systemIDs = array(
$this->config->http404PageID,
$this->config->adminRootPageID,
$this->config->trashPageID,
$this->config->loginPageID,
$config->http404PageID,
$config->adminRootPageID,
$config->trashPageID,
$config->loginPageID,
);
parent::wired();
}
public function renderChild(Page $page) {

View File

@@ -68,6 +68,7 @@ class ListerBookmarks extends Wire {
*
*/
public function __construct(Page $page, User $user) {
$page->wire($this);
$this->page = $page;
$this->user = $user;
parent::__construct();

View File

@@ -103,11 +103,14 @@ class ProcessPagesExportImport extends Process {
*
*/
protected function buildForm($tab = '') {
/** @var Modules $modules */
$modules = $this->wire('modules');
$modules->get('JqueryWireTabs');
/** @var User $user */
$user = $this->wire('user');
/** @var InputfieldForm $form */
$form = $modules->get('InputfieldForm');
$form->attr('id', 'ProcessPagesExportImport');
$form->attr('method', 'post');
@@ -131,21 +134,25 @@ class ProcessPagesExportImport extends Process {
*
*/
protected function buildImportTab() {
/** @var Modules $modules */
$modules = $this->wire('modules');
$tab = new InputfieldWrapper();
/** @var InputfieldWrapper $tab */
$tab = $this->wire(new InputfieldWrapper());
$tab->attr('id+name', 'tab_import');
$tab->attr('title', $this->_('Import'));
$tab->addClass('WireTab');
/** @var InputfieldTextarea $f */
$f = $modules->get('InputfieldTextarea');
$f->name = 'import_json';
$f->label = $this->_('Import from JSON string');
$f->icon = 'scissors';
$f->description = $this->_('Paste in the JSON string previously exported from this tool.');
$tab->add($f);
/** @var InputfieldFile $f */
$f = $modules->get('InputfieldFile');
$f->name = 'import_zip';
$f->label = $this->_('Import from ZIP file upload') . " (experimental)";
@@ -159,6 +166,7 @@ class ProcessPagesExportImport extends Process {
$f->destinationPath = $this->exportImport->getExportPath();
$tab->add($f);
/** @var InputfieldSubmit $f */
$f = $modules->get('InputfieldSubmit');
$f->attr('name', 'submit_import');
$f->val($this->_('Continue'));
@@ -180,7 +188,7 @@ class ProcessPagesExportImport extends Process {
/** @var WireInput $input */
$input = $this->wire('input');
/** @var InputfieldWrapper $importTab */
/** @var InputfieldWrapper|InputfieldForm $importTab */
$importTab = $this->buildForm('import');
$submitCommit = $input->post('submit_commit_import') ? true : false;
@@ -544,7 +552,7 @@ class ProcessPagesExportImport extends Process {
$fieldset->add($f);
}
} else {
$fieldset = new InputfieldWrapper();
$fieldset = $this->wire(new InputfieldWrapper());
}
if($numFatalItems) $a['_noCommit'] = true;
@@ -910,7 +918,7 @@ class ProcessPagesExportImport extends Process {
$modules = $this->wire('modules');
$tab = new InputfieldWrapper();
$tab = $this->wire(new InputfieldWrapper());
$tab->attr('id+name', 'tab_export');
$tab->attr('title', $this->_('Export'));
$tab->addClass('WireTab');

View File

@@ -34,6 +34,8 @@ class SessionHandlerDB extends WireSessionHandler implements Module, Configurabl
/**
* Quick reference to database
*
* @var WireDatabasePDO
*
*/
protected $database;
@@ -44,13 +46,17 @@ class SessionHandlerDB extends WireSessionHandler implements Module, Configurabl
*/
public function __construct() {
parent::__construct();
$this->database = $this->wire('database');
$this->set('useIP', 0); // track IP address?
$this->set('useUA', 0); // track user agent?
$this->set('noPS', 0); // disallow parallel sessions per user
$this->set('lockSeconds', 50); // max number of seconds to wait to obtain DB row lock
}
public function wired() {
$this->database = $this->wire('database');
parent::wired();
}
public function init() {
parent::init();
// keeps session active
@@ -172,7 +178,7 @@ class SessionHandlerDB extends WireSessionHandler implements Module, Configurabl
$table = self::dbTableName;
$seconds = (int) $seconds;
$sql = "DELETE FROM `$table` WHERE ts < DATE_SUB(NOW(), INTERVAL $seconds SECOND)";
return $this->database->exec($sql);
return $this->database->exec($sql) !== false;
}
/**

View File

@@ -150,7 +150,8 @@ class SystemUpdater extends WireData implements Module, ConfigurableModule {
// clear FileCompiler cache
$config = $this->wire('config');
if($config->templateCompile || $config->moduleCompile) {
$compiler = new FileCompiler($this->wire('config')->paths->templates);
/** @var FileCompiler $compiler */
$compiler = $this->wire(new FileCompiler($this->wire('config')->paths->templates));
$compiler->clearCache(true);
$this->message($this->_('Cleared file compiler cache'));
}