Jump to content

marc1n

Members
  • Posts

    13
  • Joined

  • Last visited

Posts posted by marc1n

  1. I discovered that in method Pages::savePageQuery calling executeQuery($query) does not throw exception at all (which is unexpected because catch block has code calculating new unique name):

    do { 
    	$result = false; 
    	$errorCode = 0;
    
    	try { 	
    		$result = false;
    		$result = $this->executeQuery($query);
    
    	} catch(Exception $e) {
    
    		$errorCode = $e->getCode();
    
    		// while setupNew() already attempts to uniqify a page name with an incrementing
    		// number, there is a chance that two processes running at once might end up with
    		// the same number, so we account for the possibility here by re-trying queries
    		// that trigger duplicate-entry exceptions 
    
    		if($errorCode == 23000 && ($page->_hasAutogenName || $options['adjustName'])) {
    			// Integrity constraint violation: 1062 Duplicate entry 'background-3552' for key 'name3894_parent_id'
    			// attempt to re-generate page name
    			$nameField = 'name';
    			// account for the duplicate possibly being a multi-language name field
    			if($this->wire('languages') && preg_match('/\b(name\d*)_parent_id\b/', $e->getMessage(), $matches)) $nameField = $matches[1]; 
    			// get either 'name' or 'name123' (where 123 is language ID)
    			$pageName = $page->$nameField;
    			// determine if current name format already has a trailing number
    			if(preg_match('/^(.+?)-(\d+)$/', $pageName, $matches)) {
    				// page already has a trailing number
    				$n = $matches[2]; 
    				$pageName = $matches[1]; 
    			}
    			$page->name = $pageName . '-' . (++$n); 
    			$query->bindValue(":$nameField", $page->name); 
    			
    		} else {
    			// a different exception that we don't catch, so re-throw it
    			throw $e;
    		}
    	}
    
    } while($errorCode == 23000); 
    
    
  2. Hello,

    Ryan once said that PW will take care of creating a name for me and it will also number-increment the name (i.e. "page-name-2") if one already exists. But when I create in admin UI a new page with name 'test' (page with that name already exists) and click "Save" button I've got an error:

    • Session: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'test-1100' for key 'name_parent_id'

    •  TemplateFile: Unknown page

    My new page and its fields data is lost!

    It is a bug or a feature?

    I use PW 2.5.26.

  3. This module doesn't work with URLs with format http://www.youtube.com/watch?v=<video-id>, because oembed service doesn't recognize such URLs. I changed in module source the way of building $oembedURL:

    $videoID = $matches[2][$key]; 
    $oembedURL = "http://www.youtube.com/oembed?url=" . urlencode("http://youtube.com/watch?v=" . $videoID) . "&format=json&maxwidth={$this->maxWidth}&maxheight={$this->maxHeight}"; 
    
    • Like 1
  4. I can see why you would want to return hidden pages, as they are still viewable even if excluded from lists and searches. Not including unpublished pages seems like the desired behavior. Maybe I'm missing something, but why would you want to redirect to an unpublished page? It should return a 404.

    My use case is such that I have unpublished pages. I am importing URL mapping from CSV. I want that import matches old URLs with these unpublished pages ID's, because perhaps I will change name of these pages before I will publish them.

  5. I'm not sure what you mean by that... Where are you importing data from? And what warnings are you getting?

    Edit: An import will only save page IDs if you're importing from ProcessRedirects. If you're importing from CSV, then it won't. Perhaps I should add that functionality in? So if a destination URI matches an existing page, we should set it to use the ID instead... Is that what you're referring to?

    I was importing from CVS. The lack of this functionality is the reason I returned to ProcessRedirects module. I don't remember text of warnings, sorry. 

  6. Thanks renobird,

    I tried Jumplinks, but it has his own problems (import save all destinations as URLs, not page ids; it generates some php warnings etc.). 

    I've returned to ProcessRedirects because these problems and because I need simple URL mapping.

    I found another problem with ProcessRedirects: it does not found hidden or unpublished destination pages.

    I've modified below code in order to work with hidden or unpublished pages (I've added "include=all" selector):

    	private function _saveRedirect($from, $to, $id = 0) {
    		$from = $this->_addUrlSlashes($from);
    		$to = $this->sanitizer->url($to);
    
    		// Not external url, if it starts with slash
    		if(substr($to, 0, 1) == "/") {
    			// if the redirect_to maps to a page, then store it's ID instead
    			if(($page = $this->pages->get("$to, include=all")) && $page->id) $to = '^' . $page->id;
    		}
    
    
  7. I seems that module dosn't work for urls (redirect-from) with UTF-8 characters. 

    This change (adding "urldecode") in file ProcessRedirect.module fixed my problem:

    public function checkRedirects($event) {  
      $url = urldecode($_SERVER['REQUEST_URI']);
    • Like 1
×
×
  • Create New...