We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50297
    • 9 Posts
    Quote from: BobRay at Apr 18, 2015, 04:40 PM
    Connector? Is that one you wrote yourself?
    I`m just webmastering this site, and it seems this plug interacting with snippets/chunks and db in some way. And you were absolutley right! After disabling this plug, everything is running perfectly! Thank you!!!
      • 3749
      • 24,544 Posts
      If you want to post the code of the plugin, maybe we can guess what it was doing.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 50297
        • 9 Posts
        Yes, have a look, please:
        require_once($modx->getOption('core_path').'components/connector/model/connector/connector.class.php');
        $Connector = new Connector($modx);
         
        $Connector->connect_elements('modChunk', $Connector->config['chunksFolder'], $Connector->config['chunkExt']);
        $Connector->connect_elements('modSnippet', $Connector->config['snippetsFolder'], $Connector->config['snippetExt']); 
         
        $Connector->disconnect_elements('modChunk', $Connector->config['chunksFolder'], $Connector->config['chunkExt']);
        $Connector->disconnect_elements('modSnippet', $Connector->config['snippetsFolder'], $Connector->config['snippetExt']);
        
        return;
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Well, that's not a lot of help, we'd need the whole 'connector' component's code to see what it's doing. The plugin's code is just initializing the Connector object, but doesn't give any indication of what the component is supposed to do. And this is why a properly designed component should have proper commenting.

          While this specifically is applied to snippet development, the principle applies to plugins as well. http://rtfm.modx.com/revolution/2.x/developing-in-modx/basic-development/snippets/how-to-write-a-good-snippet#HowtoWriteaGoodSnippet-CommentBlock

          (this is not directed to you, but to developers of snippets, plugins and components) [ed. note: sottwell last edited this post 11 years, 5 months ago.]
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 50297
            • 9 Posts
            Ah, here it is:
            <?php
            class Connector {
            	
            	function __construct(modX &$modx,array $config = array()) {
                    $this->modx =& $modx;
            		
            		$this->corePath = $this->modx->getOption('core_path').'components/connector/'; // Директория компонента
            		$this->modelPath = $this->corePath.'model/connector/'; // Директория модели
            		$this->elementsPath = $this->corePath.'elements/'; // Директория элементов
            		$this->basketPath = $this->elementsPath.'basket/'; // Директория корзины		
            
                    /* Установка значений по умолчанию */
                    $this->config = array_merge(array(
            			'charset_fs' => 'windows-1251', // Кодировка файловой системы
            			'charset_db' => 'UTF-8', // Кодировка БД			
            			'chunksFolder' => 'chunks/', 
            			'snippetsFolder' => 'snippets/',
            			'chunkExt' => 'tpl',
            			'snippetExt' => 'php'
                    ),$config);
            		
            		/* Удаление устаревшего кэша  */
            		$this->delete_folder($modx->getOption('core_path').'cache/default');
            		$this->delete_folder($modx->getOption('core_path').'cache/resource');
            		$this->delete_folder($modx->getOption('core_path').'cache/scripts');	
            		$this->delete_folder($modx->getOption('core_path').'cache/includes');
                }
            	
            	/*	===== Подключение Чанков/Сниппетов =====	*/	
            	function connect_elements($mod, $elementsFolder, $elementsExt){
            		$elementsPath = $this->elementsPath.$elementsFolder;
            		$handle = opendir($elementsPath);
            		
            		while($file = readdir($handle)){
            			if ($file != '.' and $file != '..' and preg_match("/.*?\.$elementsExt$/i", $file) and !preg_match("/connector\.php/i", $file)){
            				
            				$filename = iconv($this->config['charset_fs'], $this->config['charset_db'], str_replace('.'.$elementsExt, '', $file));
            				$el_name = preg_split('/---/', $filename);
            				if(sizeof($el_name) == 2){
            					$name = $el_name[0];
            					$description = $el_name[1];
            				}else{
            					$name = $el_name[0];
            					$description = '';					
            				}
            				$content = implode("", file($elementsPath.$file));
            				
            				$element = $this->modx->getObject($mod, array('name' => $name, 'locked' => '0'));
            				if ($element) {
            					$element->setContent($content);
            					$element->set('description',$description);
            					$element->save();
            				}else{
            					$element = $this->modx->newObject($mod);
            					$element->set('name',$name);
            					$element->set('description',$description);
            					$element->setContent($content);
            					$element->save();
            				} // if($element)
            				
            			} // if( тип файла )
            			
            		} // while($file)
            	}
            	
            	/*	===== Отключение Чанков/Сниппетов =====	*/	
            	function disconnect_elements($mod, $elementsFolder, $elementsExt){
            		$elementsPath = $this->basketPath.$elementsFolder;
            		$handle = opendir($elementsPath);
            		while($file = readdir($handle)){
            			if ($file != '.' and $file != '..' and preg_match("/.*?\.$elementsExt$/i", $file)){
            				
            				$filename = iconv($this->config['charset_fs'], $this->config['charset_db'], str_replace('.'.$elementsExt, '', $file));
            				$el_name = preg_split('/---/', $filename);
            				if(sizeof($el_name) == 2){
            					$name = $el_name[0];
            					$description = $el_name[1];
            				}else{
            					$name = $el_name[0];
            					$description = '';					
            				}
            				
            				$content = implode("", file($elementsPath.$file));
            				
            				$element = $this->modx->getObject($mod, array('name' => $name, 'locked' => 0));
            				if ($element) {
            					if($element->getContent() == $content){
            						$element->remove();
            					}
            				} // if($element)
            				
            			} // if( тип файла )
            			
            		} // while($file)
            	}
            	
            	function delete_folder($arg){
            		if(!is_dir($arg)) return;
            		$d=opendir($arg);
            		while($f=readdir($d)){
            			if($f!="."&&$f!=".."){
            				if(is_dir($arg."/".$f))
            					$this->delete_folder($arg."/".$f);
            				else 
            					unlink($arg."/".$f);
            			}
            		}
            		closedir($d);
            		rmdir($arg);
            	}
            }
              • 4172
              • 5,888 Posts
              This plugin seems to read file-based elements and recreate chunks and snippets with content from files and is clearing the cache at the same time.

              No wonder, that your chunks was allways overridden.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!