function fix_amputees()
 {
     if ($this->mode == 'test') {
         echo '<p>Would attempt to fix amputees</p>';
     } else {
         $fixer = new AmputeeFixer();
         $fixer->fix_amputees();
         $fixer->generate_report();
     }
 }
Beispiel #2
0
if (!reason_user_has_privs(get_user_id($current_user), 'db_maintenance')) {
    die('<html><head><title>Reason: Fix Amputees</title></head><body><h1>Sorry.</h1><p>You do not have permission to fix amputees.</p><p>Only Reason users who have database maintenance privileges may do that.</p></body></html>');
}
?>
	<html>
	<head>
	<title>Reason: Fix Amputees</title>
	</head>
	<body>
	<h1>Fix Amputees</h1>
	<?php 
if (empty($_POST['do_it'])) {
    ?>
	<form method="post">
	<p>Amputees are entities that do not have records in all of their tables. Amputees are generally invisible to Reason, since entities are grabbed all-at-once.</p>
	<p>When this script is run, it will find all of the amputees in Reason and fix them by creating records in the appropriate tables.</p>
	<p>This script must be run after a table is added to a type.  We should probably make this script a cron job and/or have this code be run when finishing a type.</p>
	<input type="submit" name="do_it" value="Run the script" />
	</form>
	<?php 
} else {
    connectDB(REASON_DB);
    reason_include_once('classes/amputee_fixer.php');
    $fixer = new AmputeeFixer();
    $fixer->fix_amputees();
    $fixer->generate_report();
}
?>
	</body>
	</html>
function add_entity_table_to_type($et, $type)
{
    $pub_type_id = id_of($type);
    $es = new entity_selector(id_of('master_admin'));
    $es->add_type(id_of('content_table'));
    $es->add_right_relationship($pub_type_id, relationship_id_of('type_to_table'));
    $es->add_relation('entity.name = "' . $et . '"');
    $entities = $es->run_one();
    if (empty($entities)) {
        $es2 = new entity_selector();
        $es2->add_type(id_of('content_table'));
        $es2->add_relation('entity.name = "' . $et . '"');
        $es2->set_num(1);
        $tables = $es2->run_one();
        if (!empty($tables)) {
            $table = current($tables);
            create_relationship($pub_type_id, $table->id(), relationship_id_of('type_to_table'));
            $fixer = new AmputeeFixer();
            $fixer->fix_amputees($pub_type_id);
            $fixer->generate_report();
            return true;
        }
    }
    return false;
}