/** * Create a new git repository * * Accepts a creation path, and, optionally, a source path * * @access public * @param string $repoPath repository path * @param string $source directory to source * @param bool $remoteSource reference path * @param string|null $reference * @throws \Exception * @return GitRepo */ public static function create($repoPath, $source = null, $remoteSource = false, $reference = null, $commandString = "") { if (is_dir($repoPath) && file_exists($repoPath . "/.git") && is_dir($repoPath . "/.git")) { throw new GitException(sprintf('"%s" is already a git repository', $repoPath)); } else { $repo = new self($repoPath, true, false); if (is_string($source)) { if ($remoteSource) { if (!is_dir($reference) || !is_dir($reference . '/.git')) { throw new GitException('"' . $reference . '" is not a git repository. Cannot use as reference.'); } else { if (strlen($reference)) { $reference = realpath($reference); $reference = "--reference {$reference}"; } } $repo->cloneRemote($source, $reference); } else { $repo->cloneFrom($source, $commandString); } } else { $repo->run('create'); } return $repo; } }
/** * Create a new git repository * * @param string $repository_path The repository path * @param string $source The directory to source * @return mixed * @throws \Exception if the path already exists * @throws \Exception if the path is already a GIT repository * @throws \Exception if the directory can't be created */ public static function createNew($repository_path, $source = null) { if (file_exists($repository_path) && is_dir($repository_path)) { throw new \Exception(sprintf('"%s" already exists!', $repository_path)); } elseif (file_exists($repository_path) && is_dir($repository_path) && file_exists($repository_path . "/.git") && is_dir($repository_path . "/.git")) { throw new \Exception(sprintf('"%s" is already a git repository!', $repository_path)); } else { if (!mkdir($repository_path)) { throw new \Exception(sprintf('Can not create directory "%s"!', $repository_path)); } $repo = new self($repository_path, true, false); if (is_string($source)) { $repo->cloneFrom($source); } else { $repo->run('init'); } return $repo; } }
/** * Duplicates the object * * - field_groups * - class_fields * - field_translations * - list_items * - ex_triggers * - (predicates) * * - host_fields * - class_messages * * - constraints * - ex_triggers * * @return null|string Store-like message */ function duplicate() { if (!$this->_id) { return null; } // Load all field values $this->load(); $new = new self(); $new->cloneFrom($this); $new->name .= " (Copie)"; $new->_dont_create_default_group = true; $this->_duplication_mapping = array(); if ($msg = $new->store()) { return $msg; } // field_groups foreach ($this->loadRefsGroups() as $_group) { if ($msg = $this->duplicateObject($_group, "ex_class_id", $new->_id, $_new_group)) { continue; } $fwd_field = "ex_group_id"; $fwd_value = $_new_group->_id; // class_fields foreach ($_group->loadRefsFields() as $_field) { $_exclude_fields = array("predicate_id", "subgroup_id"); if ($msg = $this->duplicateObject($_field, "ex_group_id", $_new_group->_id, $_new_field, $_exclude_fields)) { continue; } $_fwd_field = "ex_class_field_id"; $_fwd_value = $_new_field->_id; // field_translations $this->duplicateBackRefs($_field, "field_translations", $_fwd_field, $_fwd_value); // list_items $this->duplicateBackRefs($_field, "list_items", "field_id", $_fwd_value); // ex_triggers $this->duplicateBackRefs($_field, "ex_triggers", $_fwd_field, $_fwd_value); // predicates //$this->duplicateBackRefs($_field, "predicates", $_fwd_field, $_fwd_value); } // host_fields $this->duplicateBackRefs($_group, "host_fields", $fwd_field, $fwd_value); // class_messages $this->duplicateBackRefs($_group, "class_messages", $fwd_field, $fwd_value, array("predicate_id", "subgroup_id")); // subgroups $this->duplicateBackRefs($_group, "subgroups", "parent_id", $fwd_value, array("predicate_id", "subgroup_id")); } // ex_triggers $this->duplicateBackRefs($this, "ex_triggers", "ex_class_triggered_id", $new->_id); CExObject::clearLocales(); $this->_duplication_mapping = array(); return null; }