public static function PathChecker::uniquePaths in Optimizely 8.0
Same name and namespace in other branches
- 8 src/PathChecker.php \Drupal\optimizely\PathChecker::uniquePaths()
2 calls to PathChecker::uniquePaths()
- AddUpdateForm::validateForm in src/AddUpdateForm.php
- Check to make sure the project code is unique except for the default
entry which uses the account ID but should support an additional entry
to allow for custom settings.
- AjaxEnable::enableDisable in src/AjaxEnable.php
File
- src/PathChecker.php, line 109
- Contains \Drupal\optimizely\src\PathChecker
Class
- PathChecker
- Provides static methods to check path validity, etc.
Namespace
Drupal\optimizely
Code
public static function uniquePaths($target_paths, $target_oid = NULL) {
$target_paths = self::collectAlias($target_paths);
$duplicate_target_path = self::duplicateCheck($target_paths);
if (!$duplicate_target_path) {
$query = db_select('optimizely', 'o', array(
'target' => 'slave',
))
->fields('o', array(
'oid',
'project_title',
'path',
))
->condition('o.enabled', 1, '=');
if ($target_oid != NULL) {
$query = $query
->condition('o.oid', $target_oid, '<>');
}
$projects = $query
->execute();
if ($query
->countQuery()
->execute()
->fetchField() == 0) {
return array(
TRUE,
NULL,
);
}
$all_project_paths = array();
foreach ($projects as $project) {
$project_paths = unserialize($project->path);
$all_project_paths = array_merge($all_project_paths, $project_paths);
}
$all_project_paths = self::collectAlias($all_project_paths);
$all_project_paths_string = implode("\n", $all_project_paths);
foreach ($target_paths as $target_path) {
if (strpos($target_path, '*') !== FALSE) {
if (strpos($target_path, '*') !== 0) {
$target_path = substr($target_path, 0, -2);
foreach ($all_project_paths as $all_project_path) {
if (strpos($all_project_path, $target_path) === 0 && $all_project_path != $target_path) {
return array(
$project->project_title,
$target_path,
);
}
}
}
elseif (strpos($target_path, '*') === 0 && (count($target_paths) > 1 || count($all_project_paths) > 0)) {
return array(
$project->project_title,
$target_path,
);
}
if (in_array('*', $all_project_paths)) {
return array(
$project->project_title,
$target_path,
);
}
}
elseif (strpos($target_path, '?') !== FALSE) {
$target_path = substr($target_path, 0, strpos($target_path, '?'));
}
if (\Drupal::service('path.matcher')
->matchPath($target_path, $all_project_paths_string)) {
return array(
$project->project_title,
$target_path,
);
}
}
return array(
TRUE,
NULL,
);
}
else {
return array(
NULL,
$duplicate_target_path,
);
}
}