Ejemplo n.º 1
0
function category_restore($id, $param=array()) {
  global $db_central;
  global $current_user;

  if(!isset($param['version']))
    return false;

  $cat=new category($id);
  $newest=$cat->get_newest_version();

  $pg_id=postgre_escape($id);
  $pg_version=postgre_escape($param['version']);
  $pg_newest=postgre_escape($newest);
  $future=uniqid();
  $pg_future=postgre_escape($future);

  // compile version tags
  $version_tags=new tags();
  $version_tags->set("user", $current_user->username);
  $version_tags->set("date", Date("c"));
  $version_tags->set("msg", "Restore version '{$param['version']}'");
  $pg_version_tags=array_to_hstore($version_tags->data());

  $sql ="begin;";
  $sql.="insert into category (select $pg_id, tags, $pg_future, Array[$pg_newest], $pg_version_tags  from category where version=$pg_version);";
  $sql.="insert into category_rule (select $pg_id, rule_id, tags, $pg_future from category_rule where version=$pg_version);";
  $sql.="delete from category_current where category_id=$pg_id;";
  $sql.="insert into category_current values ($pg_id, $pg_future, now());";
  $sql.="commit;";

  sql_query($sql, $db_central);

  return array("status"=>true, "version"=>$future);
}
Ejemplo n.º 2
0
  function save($param=array()) {
    global $current_user;
    global $db_central;

    $sql="begin;";

    $version=uniqid();
    $parent_version=$this->get_newest_version($db_central);
    $version_tags=new tags();
    $version_tags->set("user", $current_user->username);
    $version_tags->set("date", Date("c"));
    $version_tags->set("msg", $param['msg']);

    $sql.="insert into category values ('{$this->id}', ".array_to_hstore($this->tags->data()).", '$version', Array['$parent_version'], ".array_to_hstore($version_tags->data()).");\n";

    foreach($this->rules as $id=>$rule) {
      $sql.="insert into category_rule values ('{$this->id}', '{$rule->id}', ".array_to_hstore($rule->tags->data()).", '$version');\n";
    }

    $sql.="update category_current set version='$version', now=now() where category_id='{$this->id}';\n";
    $sql.="commit;\n";

    sql_query($sql, $db_central);
  }