Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4082624
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:12:38+00:00 2026-05-20T18:12:38+00:00

I’ve got a weird problem. I’ve created a procedure in PHP that does these

  • 0

I’ve got a weird problem. I’ve created a procedure in PHP that does these things:

  1. Read data (9.000 rows) from a MySQL table
  2. Writes a row to another table
  3. Create a folder in Alfresco based on a field in the row

I’ve got this strange problem (only on one Alfresco installation, on others I don’t have the problem), after the first 2-3 rows the password for the admin user gets deleted from Alfresco (if you look in the db, you can’t find it) and so the procedure stops. I’m using Alfresco Community 3.2.

Here is the PHP code of the procedure:

   require_once("../components/com_astra/libs/AlfrescoConnect.php");
require_once("../components/com_astra/libs/FirePHPCore/fb.php");
$username = "***";
$password = "****;";
$hostname = "localhost"; 
ob_start();
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
  or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
$selected = mysql_select_db("lbs_8",$dbhandle)
  or die("Could not select examples");
$result = mysql_query("SELECT count(*) as quanti FROM ast_tabellaTemporaneaNdg");
if (!$result) {
    die('ERRORE: ' . mysql_error());
}
$totaleTabella = mysql_result($result, 0);
echo("La tabella ast_tabellaTemporaneaNdg contiene [$totaleTabella] records<br>");
echo("Conto il numero di record della vista di transcodifica<br>");
$result = mysql_query("SELECT count(*) as quanti FROM vista_ndg_normalizzati");
if (!$result) {
    die('ERRORE: ' . mysql_error());
}
$totaleVista = mysql_result($result, 0);
echo("La vista vista_ndg_normalizzati contiene [$totaleVista] records<br>");
if ($totaleTabella == $totaleVista){
    echo("Tutte le righe della tabella ast_tabellaTemporaneaNdg sono transcodificate correttamente<br>");
    echo("Saranno quindi importati [$totaleTabella] records<br>");
}else{
    echo("Non tutte le righe della tabella ast_tabellaTemporaneaNdg sono transcodificate correttamente<br>");
    echo("nella tabella ast_tabellaTemporaneaNdg sono presenti [$totaleTabella] records, di questi solo [$totaleVista] transcodificano correttamente<br>");
    $handle = fopen("ndgNonImportabili.txt", "w");
    $result = mysql_query("SELECT ndg FROM ast_tabellaTemporaneaNdg WHERE ndg NOT IN (SELECT ndg from vista_ndg_normalizzati)");
    if (!$result) {
        die('ERRORE: ' . mysql_error());
    }
    while ($row = mysql_fetch_assoc($result)){
        $ndg = "NDG: ".$row["ndg"]."\n";
        fwrite ($handle, $ndg);

    }
    fclose($handle);
    echo("Gli NDG non importabili sono stati loggati nel file ndgNonImportabili.txt<br>");
    //die("L'importazione avra' inizio solo quando tutti gli NDG saranno importabili. I motivi per cui un ndg non è importabile possono essere: incorenza fra Natura Giuridica 1 e natura giuridica 2, Incoerenza fra comune, Provincia e Regione<br>");
}
$result = mysql_query("SELECT * FROM vista_ndg_normalizzati");
//fb($result, 'risultati');
$handle = fopen("logImportazione.txt", "w");
while ($row = mysql_fetch_assoc($result)) {
    $user = "admin";
    $ndg = $row['ndg'];
    $response = AlfrescoConnect::createNDG($ndg, $user);
    $status = $response['esito'];
    if($status == "OK"){
        $ragioneSociale = mysql_real_escape_string($row['ragioneSociale']);
        $query = "SET FOREIGN_KEY_CHECKS=0";
        $resultSetKeys = mysql_query($query);
        $query = "INSERT INTO ast_Cliente (idUtente, idNaturaGiuridica,  idTipoSegmento, idRegione, idProvincia, idComune,  ragioneSociale, ndg, idNaturaGiuridica2) VALUES ";
        $query .= " (1, ".$row['idNaturaGiuridica'].", 2 , ".$row['idRegione'].", ".$row['idProvincia'].", ".$row['idComune'].", '".$ragioneSociale."', '".$ndg."', ".$row['idNaturaGiuridica2'].")";
        //fb($query);
        $resultInsert = mysql_query($query);
        if (!$resultInsert) {
            $messaggio = "Si è verificato un errore nell'importazione dell'ndg [$ndg]: [".mysql_error()."]\n";
        }else{
            $messaggio = "[$ndg] importato con successo\n";
        }
        fwrite ($handle, $messaggio);
    }else{
        $messaggio = "Si è verificato un errore nella creazione della cartella per l'ndg [$ndg] su alfresco. ERRORE: [".$response['motivazione']."]\n";
        fwrite ($handle, $messaggio);

    }
   }
fclose($handle);
echo("importazione completata: i risultati dell'importazione sono stati salvati nel file logImportazione.txt");
?> 

The folder is created by calling $response = AlfrescoConnect::createNDG($ndg, $user); where $ndg is the name of the folder and $user is the user who created it

Here is the code of AlfrescoConnect.php:

class AlfrescoConnect
{

    static public $webscriptURL = "http://localhost:8080/alfresco/service";
    static public $login = "/api/login";
    static public $login_ticket = "/api/login/ticket";
    static public $alfrescoPath = "http://localhost:8080";

    static public $alfrescoContext = "/alfresco";

    static public $upload_file_script = "/astra/upload";
    static public $uploadFile = "/astra/uploaddoc";
    static public $search_document = "/astra/cercadocumenti";
    static public $createNDG = "/astra/creandg";
    static public $createPEFPerNDG = "/astra/creapef";
    static public $searchDocumentPerConfirm = "/astra/cercadocumentoperconferma";
    static public $confirmDocument = "/astra/confermadocumenti";
    static public $getPEF = "/astra/estraidatipef";
    static public $updatePEF = "/astra/aggiornapef";
    static public $documentCounter = "/astra/contadocumenti";
    static public $userLogin = "/astra/creautente";
    static public $cancella = "/astra/managedocumentversions";
    static public $alfUsername = "admin";
    static public $alfPassword = "admin";

    static public $ticket = "";
    static public $userTicket = ""; 

    static public function Authenticate($username='') {
        //fb($username);
        if(strcmp($username,'')==0){
            if (AlfrescoConnect::isAuthenticated()) return true;
            $link = AlfrescoConnect::$webscriptURL.AlfrescoConnect::$login."?u=".AlfrescoConnect::$alfUsername."&pw=".AlfrescoConnect::$alfPassword . "&noCache=" .time();
            fb($link, "LINK");
        }else{
            AlfrescoConnect::$userTicket =  AlfrescoConnect::CustomAuthentication($username);
            return true;
        }
        try {

            //perform a http/get request to get tiket
            // Try to create a ticket
            // If the ticket fails, it means that the username and/or password are wrong
            $r= new HttpRequest($link, HttpRequest::METH_GET);
            $r->send() ;
            $http_response = $r->getResponseBody();fb($http_response, "RISPOSTA");
            $pos1 = stripos($http_response, "<ticket>");
            $pos2 = stripos($http_response, "</ticket>");
            //ceck if token is returned 
            if ($pos1<0 | !is_int($pos1) || $pos2<0 | !is_int($pos2)) {
                AlfrescoConnect::$ticket = "";
                $returnValue = false;
            } else {

                $pos1 += 8;
                $pos2 -= $pos1;
                // clean the xml info
                AlfrescoConnect::$ticket = substr($http_response, $pos1, $pos2);
                $returnValue = true;
            }
            //fb(AlfrescoConnect::$ticket);
            $_SESSION["ticket"] = AlfrescoConnect::$ticket;
            return true;

        }
        catch (Exception $e) {
            fb($e, "Eccezione");
            AlfrescoConnect::$ticket = "";
            $_SESSION["ticket"] = AlfrescoConnect::$ticket;
            return $returnValue;
        }

    }
    static public function isAuthenticated() {
        if (!isset($_SESSION["ticket"])) return false;
        $link = AlfrescoConnect::$webscriptURL.AlfrescoConnect::$login_ticket."/".$_SESSION["ticket"]."?alf_ticket=".$_SESSION["ticket"]."&noCache=" .time();
        fb($link, 'link in isauth');
        try {

            //perform a http/get request to get tiket
            // Try to create a ticket
            // If the ticket fails, it means that the username and/or password are wrong
            $r= new HttpRequest($link, HttpRequest::METH_GET);
            $r->send() ;
            $http_response = $r->getResponseBody();

            $pos1 = stripos($http_response, "<ticket>");
            $pos2 = stripos($http_response, "</ticket>");
            //ceck if token is returned 
            if ($pos1<0 | !is_int($pos1) || $pos2<0 | !is_int($pos2)) {
                return false;
            } else {

                $pos1 += 8;
                $pos2 -= $pos1;
                // clean the xml info
                if ($_SESSION["ticket"] == substr($http_response, $pos1, $pos2)) {
                    AlfrescoConnect::$ticket = $_SESSION["ticket"];
                    return true;
                }
            }
        }
        catch (Exception $e) {
            return false;
        }
    }

    static public function CustomAuthentication($username=''){

        $url = AlfrescoConnect::$webscriptURL.AlfrescoConnect::$userLogin;
        if ($auth) {
            if (!AlfrescoConnect::Authenticate()) return -1;
            $url .= "?alf_ticket=".AlfrescoConnect::$ticket;
        }
        $parameter = array('username' => $username);
//      
        $response = AlfrescoConnect::Query($url, $parameter,HttpRequest::METH_POST,1,0);fb($url);fb($parameter);
        fb($response,'custom authentication result');

        return $response;
    }

    * perform query on alfresco webscripts
    *
    * @param    string  $url  alfresco webscript url
    * @param    string  $params parameter for the query
    * @param    string  $meth metohod for http request HTTP_METH_POST/HTTP_METH_GET default HTTP_METH_POST
    * @param    boolean $auth set whether or not to need authentication
    * @return   mixed   -1 for authentication faliure, -2 for query faliure
    */
    static public function Query($url, $params, $meth = HTTP_METH_POST, $auth = 1, $decode = 1, $ticketUser='') {
        //Aggiunto per evitare il caching 
        //fb($url, "Query url");
        //fb($params, "Query params");
        //print_r(debug_backtrace());
        $nocache=time();
        $params['nocache']=$nocache;
        if ($auth) {
            if(strcmp($ticketUser,'')==0){

                if (!AlfrescoConnect::Authenticate()) return -1;
                $params['alf_ticket'] = AlfrescoConnect::$ticket;
            }
            else{

                $params['alf_ticket'] = $ticketUser;
            }

        }
        fb($params,'param');
        try {
            //fb("invio della richiesta");
            $url=$url."?nocache=$nocache";
            $r= new HttpRequest($url, $meth);
            $r->addQueryData($params);
            $r->send() ;
            fb($r);
            $http_response = $r->getResponseBody();
            fb($http_response);
            if (!$decode) return $http_response;


            $json = new Services_JSON();

            return object2array($json->decode($http_response));

            //return json_decode($http_response, true);
        }
        catch (Exception $e) {
            return -2;
        }
    }   

    /**
     * Azioni su Alfresco
     * 
     */

    static public function createNDG($ndg, $user){
        $url = AlfrescoConnect::$webscriptURL.AlfrescoConnect::$createNDG;
        fb("Crea l'ndg,$url");
        if (strcmp($user,'')!=0) {
            $ticket = AlfrescoConnect::Authenticate($user);
            if (!$ticket) return -1;
        }
        $parameter = array(ModelParameter::$ndg => $ndg);

        $response = AlfrescoConnect::Query($url, $parameter,HTTP_METH_POST,1,1,AlfrescoConnect::$userTicket);

        return $response;

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:12:39+00:00Added an answer on May 20, 2026 at 6:12 pm

    It was a memory problem. Never ever try to run Alfresco on a machine with only 1GB of memory!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I want to count how many characters a certain string has in PHP, but
I have a JSP page retrieving data and when single or double quotes are
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.