<commit_before><?php


class ShortcodesConverterTask extends BuildTask {
	
	public function run($request) {
		if (!(DB::getConn() instanceof MySQLDatabase)){
			user_error('Sorry this task only runs on Mysql for the moment');
		}
		if (Director::is_cli() || Permission::check('ADMIN')){
			$dataClasses = ClassInfo::subclassesFor('DataObject');
			$htmlTextClasses = ClassInfo::subclassesFor('HTMLText');
			array_shift($dataClasses);
			foreach($dataClasses as $dataClass){
				$fields = DataObject::custom_database_fields($dataClass);
				echo "\n Inspecting class ".$dataClass."\n";
				foreach($fields as $fieldName=>$fieldType){
					if (in_array($fieldType, $htmlTextClasses)){
						echo "Field ".$fieldName." is of type HTMLText (or descendant) and is now converted\n";
						DB::query("UPDATE \"$dataClass\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[sitetree_link%20', '[sitetree_link,')"); 
						DB::query("UPDATE \"$dataClass\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[document_link%20', '[document_link,')"); 
						if (Object::has_extension($dataClass, 'Versioned')){
							DB::query("UPDATE \"{$dataClass}_Live\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[sitetree_link%20', '[sitetree_link,')"); 
							DB::query("UPDATE \"{$dataClass}_Live\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[document_link%20', '[document_link,')"); 
							DB::query("UPDATE \"{$dataClass}_versions\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[sitetree_link%20', '[sitetree_link,')"); 
							DB::query("UPDATE \"{$dataClass}_versions\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[document_link%20', '[document_link,')"); 
						}
					}
				}
			}
		}
	}
}<commit_msg>MINOR Also converts when there's a space instead of %20<commit_after><?php


class ShortcodesConverterTask extends BuildTask {
	
	public function run($request) {
		if (!(DB::getConn() instanceof MySQLDatabase)){
			user_error('Sorry this task only runs on Mysql for the moment');
		}
		if (Director::is_cli() || Permission::check('ADMIN')){
			$dataClasses = ClassInfo::subclassesFor('DataObject');
			$htmlTextClasses = ClassInfo::subclassesFor('HTMLText');
			array_shift($dataClasses);
			foreach($dataClasses as $dataClass){
				$fields = DataObject::custom_database_fields($dataClass);
				echo "\n Inspecting class ".$dataClass."\n";
				foreach($fields as $fieldName=>$fieldType){
					if (in_array($fieldType, $htmlTextClasses)){
						echo "Field ".$fieldName." is of type HTMLText (or descendant) and is now converted\n";
						
						DB::query("UPDATE \"$dataClass\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[sitetree_link%20', '[sitetree_link,')"); 
						DB::query("UPDATE \"$dataClass\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[sitetree_link ', '[sitetree_link,')");
						DB::query("UPDATE \"$dataClass\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[document_link%20', '[document_link,')"); 
						DB::query("UPDATE \"$dataClass\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[document_link ', '[document_link,')"); 
						if (Object::has_extension($dataClass, 'Versioned')){
							echo "Class ".$dataClass." is versioned; converting live and versioned records too\n";
							DB::query("UPDATE \"{$dataClass}_Live\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[sitetree_link%20', '[sitetree_link,')"); 
							DB::query("UPDATE \"{$dataClass}_Live\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[sitetree_link ', '[sitetree_link,')"); 
							DB::query("UPDATE \"{$dataClass}_Live\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[document_link%20', '[document_link,')"); 
							DB::query("UPDATE \"{$dataClass}_Live\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[document_link ', '[document_link,')");
							DB::query("UPDATE \"{$dataClass}_versions\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[sitetree_link%20', '[sitetree_link,')"); 
							DB::query("UPDATE \"{$dataClass}_versions\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[sitetree_link ', '[sitetree_link,')");
							DB::query("UPDATE \"{$dataClass}_versions\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[document_link%20', '[document_link,')"); 
							DB::query("UPDATE \"{$dataClass}_versions\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '[document_link ', '[document_link,')"); 
						}
					}
				}
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.21352477999073646, 'fraction_numerical': 0.006021306160259379, 'mean_word_length': 4.781793842034806, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '634940', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1385, 'n_words': 270}