Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/13/2022 in all areas

  1. I guess this should do the trick (delete orphaned images) // before the function definition: $imageFields = array(); // hold all image field-names // replace/insert in my above function this: // tell PW that all the data needs to be saved foreach ($copy->fieldgroup as $field) { if ($field->type !== "FieldtypeImage") { if ($copy->hasField($field)) $copy->trackChange($field->name); } else { $imageFields[] = $field->name; // here } } // test it: $pg = $pages->get(23506); // clone a page $newClone = cloneWithoutFiles($pg); $id = $newClone->id; // echo "new page id = $id <br>"; $pg = $pages->get($id); $pg->of(false); foreach($imageFields as $f) { $pg->$f->deleteAll(); $pg->save($f); } Perhaps there's a cleaner way to do all this... it would be nice to have this as an option built into the core function!
    2 points
  2. ProcessWire Docker Image Dockerized Processwire installation and development enviroment Local enviroment with MariaDB container included Mount local filesystem Processwire versions VSCode Itelliphense configuration xDebug preconfigured Opcache + JIT ready (xDebug must be disabled) Installation & usage Development enviroment installation Build using local script $ git clone https://github.com/laikmosh/docker-processwire.git $ cd docker-processwire $ docker-compose up Install as usual, no extra configuration is needed. There is a config-dev.php file in the ./site/ folder, this file will load by default when running locally, but is in the .dockerignore, so it wont be included at image building time. Custom php.ini settings can be set at: /Processwire/scripts/php/php.ini *Image must be rebuilt for changes on php.ini to take effect Development enviroment usage By default the ProcessWire installer will load the `.env` configuration. Configure .env file for project and DB settings, default database credentials are: Database: {COMPOSE_PROJECT_NAME} User: admin Password: password Server: database Port: 3306 Editable files and templates will be installed to the ./site/ folder. Processwire documentation ProcessWire ProcessWire Repo ProcessWire Documentation
    1 point
  3. I think the best solution would be to ask Ryan to add an option "copyFiles" to the clone method. It would be very easy to add and I think everything that can help with performance is a welcome addition to Ryan ?
    1 point
  4. Basically, you could clone the clone function (ha!) from the core and alter it slightly: https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/Pages.php#L1733 function cloneWithoutFiles(Page $page, Page $parent = null, $recursive = true, $options = array()) { $defaults = array( 'forceID' => 0, 'set' => array(), 'recursionLevel' => 0, // recursion level (internal use only) ); if (is_string($options)) $options = Selectors::keyValueStringToArray($options); $options = array_merge($defaults, $options); if ($parent === null) $parent = $page->parent; if (count($options['set']) && !empty($options['set']['name'])) { $name = $options['set']['name']; } else { $name = wire()->pages->names()->uniquePageName(array( 'name' => $page->name, 'parent' => $parent )); } $of = $page->of(); $page->of(false); // Ensure all data is loaded for the page foreach ($page->fieldgroup as $field) { // changed: if ($field->type !== "FieldtypeImage") { if ($page->hasField($field->name)) $page->get($field->name); } } /** @var User $user */ $user = wire()->wire('user'); // clone in memory $copy = clone $page; $copy->setIsNew(true); $copy->of(false); $copy->setQuietly('_cloning', $page); $copy->setQuietly('id', $options['forceID'] > 1 ? (int)$options['forceID'] : 0); $copy->setQuietly('numChildren', 0); $copy->setQuietly('created', time()); $copy->setQuietly('modified', time()); $copy->name = $name; $copy->parent = $parent; if (!isset($options['quiet']) || $options['quiet']) { $options['quiet'] = true; $copy->setQuietly('created_users_id', $user->id); $copy->setQuietly('modified_users_id', $user->id); } // set any properties indicated in options if (count($options['set'])) { foreach ($options['set'] as $key => $value) { $copy->set($key, $value); // quiet option required for setting modified time or user if ($key === 'modified' || $key === 'modified_users_id') $options['quiet'] = true; } } // tell PW that all the data needs to be saved foreach ($copy->fieldgroup as $field) { // changed: if ($field->type !== "FieldtypeImage") { if ($copy->hasField($field)) $copy->trackChange($field->name); } } wire()->pages->cloneReady($page, $copy); wire()->cloning++; $options['ignoreFamily'] = true; // skip family checks during clone try { wire()->pages->save($copy, $options); } catch (\Exception $e) { wire()->cloning--; $copy->setQuietly('_cloning', null); $page->of($of); throw $e; } wire()->cloning--; // check to make sure the clone has worked so far if (!$copy->id || $copy->id == $page->id) { $copy->setQuietly('_cloning', null); $page->of($of); return wire()->pages->newNullPage(); } // copy $page's files over to new page // changed: // basically, you could delete this block altogether if (PagefilesManager::hasFiles($page)) { // $copy->filesManager->init($copy); // $page->filesManager->copyFiles($copy->filesManager->path()); } // if there are children, then recursively clone them too if ($page->numChildren && $recursive) { $start = 0; $limit = 200; $numChildrenCopied = 0; do { $children = $page->children("include=all, start=$start, limit=$limit"); $numChildren = $children->count(); foreach ($children as $child) { /** @var Page $child */ $childCopy = wire()->pages->clone($child, $copy, true, array( 'recursionLevel' => $options['recursionLevel'] + 1, )); if ($childCopy->id) $numChildrenCopied++; } $start += $limit; wire()->pages->uncacheAll(); } while ($numChildren); $copy->setQuietly('numChildren', $numChildrenCopied); } $copy->parentPrevious = null; $copy->setQuietly('_cloning', null); if ($options['recursionLevel'] === 0) { // update pages_parents table, only when at recursionLevel 0 since parents()->rebuild() already descends if ($copy->numChildren) { $copy->setIsNew(true); wire()->pages->parents()->rebuild($copy); $copy->setIsNew(false); } // update sort if ($copy->parent()->sortfield() == 'sort') { wire()->sortPage($copy, $copy->sort, true); } } $copy->of($of); $page->of($of); $page->meta()->copyTo($copy->id); $copy->resetTrackChanges(); wire()->pages->cloned($page, $copy); wire()->pages->debugLog('clone', "page=$page, parent=$parent", $copy); return $copy; } // basic usage just as with original function: $pg = $pages->get(23506); cloneWithoutFiles($pg); Besides the three places marked with // changed, I also had to replace $this-> with wire()-> to use it in a template file. Images (files) are not copied to the new page, however, the fields are. It wouldn't be too hard to delete these after you've created the clone (after initial clone-save).
    1 point
  5. @bernhard, thanks with the latest version you provided it works now.
    1 point
  6. It's a fun topic. Look ma - no magenta exists. ? And a cool one I found in college somewhere between the bronze and iron age - creating colors that don't exist with Wendy Carlos: https://www.wendycarlos.com/colorvis/color.html Do you see color in this image? Funny, its just made up of red and grayscale pixels.
    1 point
  7. You could call $modules->getModuleInfo('all', ['minify' => false]) and iterate over the results. Each entry has a "core" property and an "installed" property you can check.
    1 point
  8. Thx @Juergen that also helped me today. This is what I came up with (for future reference) when I needed to add a page clone button: /** * Add clone button to form */ public function addCloneButton() { // add button to form $this->addHookAfter("ProcessPageEdit::buildForm", function($event) { $form = $event->arguments(0); $form->add([ 'type' => 'submit', 'name' => 'btn_clone_plan', 'value' => __('Clone'), 'icon' => 'clone', ]); $form->get('btn_clone_plan')->addClass('ui-priority-secondary'); }); // process input $this->addHookAfter("ProcessPageEdit::processInput", function($event) { $form = $event->arguments(0); if($form != "InputfieldForm") return; // dont fire on inputfields if($this->input->post('btn_clone_plan')) { // tell PW to save the page $this->input->post->submit_save = 1; } if(count($form->getErrors())) { // clone only if there are no errors, otherwise do a regular save unset($this->input->post->btn_clone_plan); } }); // do the clone $this->addHookAfter("Pages::saved", function($event) { if(!$this->input->post->btn_clone_plan) return; unset($this->input->post->btn_clone_plan); // prevent endless loop! $clone = $this->pages->clone($event->arguments(0)); $this->session->redirect($clone->editUrl); }); } PS: This approach might be easier, but I wanted an extra button:
    1 point
  9. I'm sure you'll love it I'm glad you chose my blogpost as a tutorial but keep in mind that this was intended to show how to build process modules. I guess there are better resources for regular modules out there edit: just saw you already mentioned it: yes, you don't need a process module for that. i created the tutorial because there are lots of tutorials and examples of how to create regular modules but only very few that cover process modules. creating your own fields (fieldtype/inputfield modules) is a little more complex. i would recommend you start by creating a simple module that loads some javascript, hooks into something (like modifying markup of other fields) this is a simple example of one of my first modules that covers lots of basic principles and that you can use for learning: https://github.com/BernhardBaumrock/TemplatePreviewImages (note that $config->scripts->add() only works when the fields are not ajax loaded)
    1 point
  10. I upgraded jQuery from 1.8.3 to 1.12.1, jQuery UI from 1.10.4 to 1.12.1, datepicker.js from 1.6.1 to 1.6.3 and updated longclick.js from 0.3.2 to 0.4.0 and it works just fine (after few quick tests). Then I tried jQuery 3.2.1 and jQuery Migrate 1.4.1 and it's working too (Migrate is required). jQuery 1.8.3 is released in november 2012. It's nothing wrong with that old version, but it just doesn't fit in the incoming new stable version of PW...
    1 point
×
×
  • Create New...