<commit_before><?php
#
# Copyright (c) 2006-2015 University of Utah and the Flux Group.
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
#
#
class WebTask {
    var	$webtask;
    var $decoded = null;

    #
    # Constructor by lookup on unique ID
    #
    function WebTask($task_id) {
	$safe_id = addslashes($task_id);

	$query_result =
	    DBQueryWarn("select * from web_tasks ".
			"where task_id='$safe_id'");

	if (!$query_result || !mysql_num_rows($query_result)) {
	    $this->webtask = NULL;
	    return;
	}
	$this->webtask = mysql_fetch_array($query_result);
    }

    # Hmm, how does one cause an error in a php constructor?
    function IsValid() {
	return !is_null($this->webtask);
    }

    # Lookup by imageid
    function Lookup($id) {
	$foo = new WebTask($id);

	if (! $foo->IsValid())
	    return null;

	return $foo;
    }

    # Lookup by object.
    function LookupByObject($uuid) {
	$query_result =
	    DBQueryWarn("select task_id from web_tasks ".
			"where object_uuid='$uuid'");

	if (!$query_result || !mysql_num_rows($query_result)) {
	    return null;
	}
	$row = mysql_fetch_array($query_result);
	$idx = $row['task_id'];
	
	return WebTask::Lookup($idx);
    }

    #
    # Create an anonymous web task (not associated with an object). This
    # is useful when using a webtask to create a new object via a backend
    # script.
    #
    function CreateAnonymous() {
        $task_id = WebTask::GenerateID();

        $query_result = 
            DBQueryWarn("insert into web_tasks set task_id='$task_id', ".
                        "  created=now(), object_uuid='$task_id'");
	if (!$query_result || !mysql_num_rows($query_result)) {
            return null;
        }
        return WebTask::Lookup($task_id);
    }

    function Refresh($task_id) {
	if (! $this->IsValid())
	    return -1;
        $task_id = $this->task_id();

	$query_result =
	    DBQueryWarn("select * from web_tasks ".
			"where task_id='$task_id'");

	if (!$query_result || !mysql_num_rows($query_result)) {
	    $this->webtask = NULL;
	    return -1;
	}
	$this->webtask = mysql_fetch_array($query_result);
        return 0;
    }

    # We delete from the web interface.
    function Delete() {
	$task_id = $this->task_id();
	DBQueryWarn("delete from web_tasks where task_id='$task_id'");
	return 0;
    }

    # accessors<commit_msg>Minor bug fix.<commit_after><?php
#
# Copyright (c) 2006-2015 University of Utah and the Flux Group.
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
#
#
class WebTask {
    var	$webtask;
    var $decoded = null;

    #
    # Constructor by lookup on unique ID
    #
    function WebTask($task_id) {
	$safe_id = addslashes($task_id);

	$query_result =
	    DBQueryWarn("select * from web_tasks ".
			"where task_id='$safe_id'");

	if (!$query_result || !mysql_num_rows($query_result)) {
	    $this->webtask = NULL;
	    return;
	}
	$this->webtask = mysql_fetch_array($query_result);
    }

    # Hmm, how does one cause an error in a php constructor?
    function IsValid() {
	return !is_null($this->webtask);
    }

    # Lookup by imageid
    function Lookup($id) {
	$foo = new WebTask($id);

	if (! $foo->IsValid())
	    return null;

	return $foo;
    }

    # Lookup by object.
    function LookupByObject($uuid) {
	$query_result =
	    DBQueryWarn("select task_id from web_tasks ".
			"where object_uuid='$uuid'");

	if (!$query_result || !mysql_num_rows($query_result)) {
	    return null;
	}
	$row = mysql_fetch_array($query_result);
	$idx = $row['task_id'];
	
	return WebTask::Lookup($idx);
    }

    #
    # Create an anonymous web task (not associated with an object). This
    # is useful when using a webtask to create a new object via a backend
    # script.
    #
    function CreateAnonymous() {
        $task_id = WebTask::GenerateID();

        $query_result = 
            DBQueryWarn("insert into web_tasks set task_id='$task_id', ".
                        "  created=now(), object_uuid='$task_id'");
        
	if (!$query_result) {
            return null;
        }
        return WebTask::Lookup($task_id);
    }

    function Refresh($task_id) {
	if (! $this->IsValid())
	    return -1;
        $task_id = $this->task_id();

	$query_result =
	    DBQueryWarn("select * from web_tasks ".
			"where task_id='$task_id'");

	if (!$query_result || !mysql_num_rows($query_result)) {
	    $this->webtask = NULL;
	    return -1;
	}
	$this->webtask = mysql_fetch_array($query_result);
        return 0;
    }

    # We delete from the web interface.
    function Delete() {
	$task_id = $this->task_id();
	DBQueryWarn("delete from web_tasks where task_id='$task_id'");
	return 0;
    }

    # accessors
{'fraction_non_alphanumeric': 0.12074661380905187, 'fraction_numerical': 0.004294681202510736, 'mean_word_length': 3.055592766242465, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3048292', 'n_tokens_mistral': 2027, 'n_tokens_neox': 1946, 'n_words': 590}